10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7862SRichard.Bean@Sun.COM * Common Development and Distribution License (the "License").
6*7862SRichard.Bean@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*7862SRichard.Bean@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/atomic.h>
280Sstevel@tonic-gate #include <sys/systm.h>
290Sstevel@tonic-gate #include <sys/socket.h>
300Sstevel@tonic-gate #include <netinet/in.h>
310Sstevel@tonic-gate #include <sys/modctl.h>
320Sstevel@tonic-gate #include <sys/sunddi.h>
330Sstevel@tonic-gate #include <ipp/ipp.h>
340Sstevel@tonic-gate #include <ipp/ipp_config.h>
350Sstevel@tonic-gate #include <inet/common.h>
360Sstevel@tonic-gate #include <ipp/dlcosmk/dlcosmk_impl.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate #define D_SM_COMMENT "IPP dlcosmk marker module"
390Sstevel@tonic-gate
400Sstevel@tonic-gate /* DDI file for dlcosmk ipp module */
410Sstevel@tonic-gate
420Sstevel@tonic-gate static int dlcosmk_create_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
430Sstevel@tonic-gate static int dlcosmk_modify_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
440Sstevel@tonic-gate static int dlcosmk_destroy_action(ipp_action_id_t, ipp_flags_t);
450Sstevel@tonic-gate static int dlcosmk_info(ipp_action_id_t, int (*)(nvlist_t *, void *), void *,
460Sstevel@tonic-gate ipp_flags_t);
470Sstevel@tonic-gate static int dlcosmk_invoke_action(ipp_action_id_t, ipp_packet_t *);
480Sstevel@tonic-gate
490Sstevel@tonic-gate static int dlcosmk_statinit(ipp_action_id_t, dlcosmk_data_t *);
500Sstevel@tonic-gate static int dlcosmk_update_stats(ipp_stat_t *, void *, int);
510Sstevel@tonic-gate
520Sstevel@tonic-gate /* Entry points for this IPP module */
530Sstevel@tonic-gate ipp_ops_t dlcosmk_ops = {
540Sstevel@tonic-gate IPPO_REV,
550Sstevel@tonic-gate dlcosmk_create_action, /* ippo_action_create */
560Sstevel@tonic-gate dlcosmk_modify_action, /* ippo_action_modify */
570Sstevel@tonic-gate dlcosmk_destroy_action, /* ippo_action_destroy */
580Sstevel@tonic-gate dlcosmk_info, /* ippo_action_info */
590Sstevel@tonic-gate dlcosmk_invoke_action /* ippo_action_invoke */
600Sstevel@tonic-gate };
610Sstevel@tonic-gate
620Sstevel@tonic-gate extern struct mod_ops mod_ippops;
630Sstevel@tonic-gate
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate * Module linkage information for the kernel.
660Sstevel@tonic-gate */
670Sstevel@tonic-gate static struct modlipp modlipp = {
680Sstevel@tonic-gate &mod_ippops,
69*7862SRichard.Bean@Sun.COM D_SM_COMMENT,
700Sstevel@tonic-gate &dlcosmk_ops
710Sstevel@tonic-gate };
720Sstevel@tonic-gate
730Sstevel@tonic-gate static struct modlinkage modlinkage = {
740Sstevel@tonic-gate MODREV_1,
750Sstevel@tonic-gate (void *)&modlipp,
760Sstevel@tonic-gate NULL
770Sstevel@tonic-gate };
780Sstevel@tonic-gate
790Sstevel@tonic-gate
800Sstevel@tonic-gate int
_init(void)810Sstevel@tonic-gate _init(void)
820Sstevel@tonic-gate {
830Sstevel@tonic-gate return (mod_install(&modlinkage));
840Sstevel@tonic-gate }
850Sstevel@tonic-gate
860Sstevel@tonic-gate int
_fini(void)870Sstevel@tonic-gate _fini(void)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate return (mod_remove(&modlinkage));
900Sstevel@tonic-gate }
910Sstevel@tonic-gate
920Sstevel@tonic-gate int
_info(struct modinfo * modinfop)930Sstevel@tonic-gate _info(struct modinfo *modinfop)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
960Sstevel@tonic-gate }
970Sstevel@tonic-gate
980Sstevel@tonic-gate static int
dlcosmk_create_action(ipp_action_id_t aid,nvlist_t ** nvlpp,ipp_flags_t flags)990Sstevel@tonic-gate dlcosmk_create_action(ipp_action_id_t aid, nvlist_t **nvlpp,
1000Sstevel@tonic-gate ipp_flags_t flags)
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate nvlist_t *nvlp;
1030Sstevel@tonic-gate dlcosmk_data_t *dlcosmk_data;
1040Sstevel@tonic-gate char *next_action;
1050Sstevel@tonic-gate int err;
1060Sstevel@tonic-gate uint32_t bstats, param;
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate ASSERT((nvlpp != NULL) && (*nvlpp != NULL));
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate nvlp = *nvlpp;
1110Sstevel@tonic-gate *nvlpp = NULL; /* nvlist should be NULL on return */
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate if ((dlcosmk_data = kmem_zalloc(DLCOSMK_DATA_SZ, KM_NOSLEEP)) == NULL) {
1140Sstevel@tonic-gate nvlist_free(nvlp);
1150Sstevel@tonic-gate return (ENOMEM);
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate /* parse next action name */
1190Sstevel@tonic-gate if ((err = nvlist_lookup_string(nvlp, DLCOSMK_NEXT_ACTION_NAME,
1200Sstevel@tonic-gate &next_action)) != 0) {
1210Sstevel@tonic-gate nvlist_free(nvlp);
1220Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: invalid config, "\
1230Sstevel@tonic-gate "next_action name missing\n"));
1240Sstevel@tonic-gate kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
1250Sstevel@tonic-gate return (err);
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate if ((dlcosmk_data->next_action =
1280Sstevel@tonic-gate ipp_action_lookup(next_action)) == IPP_ACTION_INVAL) {
1290Sstevel@tonic-gate nvlist_free(nvlp);
1300Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: next_action invalid\n"));
1310Sstevel@tonic-gate kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
1320Sstevel@tonic-gate return (EINVAL);
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate /* parse cos - from the config file */
1360Sstevel@tonic-gate if ((err = nvlist_lookup_byte(nvlp, DLCOSMK_COS,
1370Sstevel@tonic-gate &dlcosmk_data->usr_pri)) != 0) {
1380Sstevel@tonic-gate nvlist_free(nvlp);
1390Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: invalid config, "\
1400Sstevel@tonic-gate "cos missing\n"));
1410Sstevel@tonic-gate kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
1420Sstevel@tonic-gate return (err);
1430Sstevel@tonic-gate }
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate /* parse b_band - mapped from cos */
1460Sstevel@tonic-gate if ((err = nvlist_lookup_uint32(nvlp, DLCOSMK_BAND, ¶m)) != 0) {
1470Sstevel@tonic-gate nvlist_free(nvlp);
1480Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: invalid config, "\
1490Sstevel@tonic-gate "b_band missing\n"));
1500Sstevel@tonic-gate kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
1510Sstevel@tonic-gate return (err);
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate dlcosmk_data->b_band = param;
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate /* parse dl_priority.dl_max - mapped from cos */
1560Sstevel@tonic-gate if ((err = nvlist_lookup_uint32(nvlp, DLCOSMK_PRI, ¶m)) != 0) {
1570Sstevel@tonic-gate nvlist_free(nvlp);
1580Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: invalid config, "\
1590Sstevel@tonic-gate "dl_priority missing\n"));
1600Sstevel@tonic-gate kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
1610Sstevel@tonic-gate return (err);
1620Sstevel@tonic-gate }
1630Sstevel@tonic-gate dlcosmk_data->dl_max = param;
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate /* parse gather_stats boolean */
1660Sstevel@tonic-gate if ((err = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE, &bstats))
1670Sstevel@tonic-gate != 0) {
1680Sstevel@tonic-gate dlcosmk_data->gather_stats = B_FALSE;
1690Sstevel@tonic-gate } else {
1700Sstevel@tonic-gate /* If stats is needed, initialize the stats structure */
1710Sstevel@tonic-gate dlcosmk_data->gather_stats = (bstats != 0) ? B_TRUE : B_FALSE;
1720Sstevel@tonic-gate if (dlcosmk_data->gather_stats) {
1730Sstevel@tonic-gate if ((err = dlcosmk_statinit(aid, dlcosmk_data)) != 0) {
1740Sstevel@tonic-gate nvlist_free(nvlp);
1750Sstevel@tonic-gate kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
1760Sstevel@tonic-gate return (err);
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate /* Free the nvlist */
1820Sstevel@tonic-gate nvlist_free(nvlp);
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate /* set action chain reference */
1850Sstevel@tonic-gate if ((err = ipp_action_ref(aid, dlcosmk_data->next_action,
1860Sstevel@tonic-gate flags)) != 0) {
1870Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: ipp_action_ref " \
1880Sstevel@tonic-gate "returned with error %d\n", err));
1890Sstevel@tonic-gate ipp_stat_destroy(dlcosmk_data->stats);
1900Sstevel@tonic-gate kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
1910Sstevel@tonic-gate return (err);
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate ipp_action_set_ptr(aid, (void *)dlcosmk_data);
1950Sstevel@tonic-gate return (0);
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate static int
dlcosmk_modify_action(ipp_action_id_t aid,nvlist_t ** nvlpp,ipp_flags_t flags)1990Sstevel@tonic-gate dlcosmk_modify_action(ipp_action_id_t aid, nvlist_t **nvlpp, ipp_flags_t flags)
2000Sstevel@tonic-gate {
2010Sstevel@tonic-gate nvlist_t *nvlp;
2020Sstevel@tonic-gate int err = 0;
2030Sstevel@tonic-gate uint32_t band, dlpri;
2040Sstevel@tonic-gate uint8_t config_type;
2050Sstevel@tonic-gate uint8_t cos;
2060Sstevel@tonic-gate char *next_action_name;
2070Sstevel@tonic-gate ipp_action_id_t next_action;
2080Sstevel@tonic-gate dlcosmk_data_t *dlcosmk_data;
2090Sstevel@tonic-gate uint32_t bstats;
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate ASSERT((nvlpp != NULL) && (*nvlpp != NULL));
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate nvlp = *nvlpp;
2140Sstevel@tonic-gate *nvlpp = NULL; /* nvlist should be NULL when this returns */
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate if ((err = nvlist_lookup_byte(nvlp, IPP_CONFIG_TYPE, &config_type))
2170Sstevel@tonic-gate != 0) {
2180Sstevel@tonic-gate nvlist_free(nvlp);
2190Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_modify_action: invalid configuration "\
2200Sstevel@tonic-gate "type\n"));
2210Sstevel@tonic-gate return (err);
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate
2240Sstevel@tonic-gate if (config_type != IPP_SET) {
2250Sstevel@tonic-gate nvlist_free(nvlp);
2260Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_modify_action: invalid configuration "\
2270Sstevel@tonic-gate "type %d\n", config_type));
2280Sstevel@tonic-gate return (EINVAL);
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate dlcosmk_data = (dlcosmk_data_t *)ipp_action_get_ptr(aid);
2320Sstevel@tonic-gate ASSERT(dlcosmk_data != NULL);
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate /* parse next action name, if present */
2350Sstevel@tonic-gate if ((err = nvlist_lookup_string(nvlp, DLCOSMK_NEXT_ACTION_NAME,
2360Sstevel@tonic-gate &next_action_name)) == 0) {
2370Sstevel@tonic-gate /* lookup action name to get action id */
2380Sstevel@tonic-gate if ((next_action = ipp_action_lookup(next_action_name))
2390Sstevel@tonic-gate == IPP_ACTION_INVAL) {
2400Sstevel@tonic-gate nvlist_free(nvlp);
2410Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_modify_action: next_action "\
2420Sstevel@tonic-gate "invalid\n"));
2430Sstevel@tonic-gate return (EINVAL);
2440Sstevel@tonic-gate }
2450Sstevel@tonic-gate /* reference new action */
2460Sstevel@tonic-gate if ((err = ipp_action_ref(aid, next_action, flags)) != 0) {
2470Sstevel@tonic-gate nvlist_free(nvlp);
2480Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_modify_action: ipp_action_ref "\
2490Sstevel@tonic-gate "returned with error %d\n", err));
2500Sstevel@tonic-gate return (err);
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate /* unref old action */
2530Sstevel@tonic-gate err = ipp_action_unref(aid, dlcosmk_data->next_action, flags);
2540Sstevel@tonic-gate ASSERT(err == 0);
2550Sstevel@tonic-gate dlcosmk_data->next_action = next_action;
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate
2580Sstevel@tonic-gate /* parse cos, if present */
2590Sstevel@tonic-gate if ((err = nvlist_lookup_byte(nvlp, DLCOSMK_COS, &cos)) == 0) {
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate /* parse b_band, mapped from cos */
2620Sstevel@tonic-gate if ((err = nvlist_lookup_uint32(nvlp, DLCOSMK_BAND,
2630Sstevel@tonic-gate &band)) != 0) {
2640Sstevel@tonic-gate nvlist_free(nvlp);
2650Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_modify_action: b_band not "\
2660Sstevel@tonic-gate "provided\n"));
2670Sstevel@tonic-gate return (err);
2680Sstevel@tonic-gate }
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate /* parse dl_priority, mapped from cos */
2710Sstevel@tonic-gate if ((err = nvlist_lookup_uint32(nvlp, DLCOSMK_PRI,
2720Sstevel@tonic-gate &dlpri)) != 0) {
2730Sstevel@tonic-gate nvlist_free(nvlp);
2740Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_modify_action: dl_priority not "\
2750Sstevel@tonic-gate "provided\n"));
2760Sstevel@tonic-gate return (err);
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate /* Have all the three values, change them */
2800Sstevel@tonic-gate dlcosmk_data->usr_pri = cos;
2810Sstevel@tonic-gate dlcosmk_data->b_band = band;
2820Sstevel@tonic-gate dlcosmk_data->dl_max = dlpri;
2830Sstevel@tonic-gate }
2840Sstevel@tonic-gate
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate /* parse gather_stats boolean, if present */
2870Sstevel@tonic-gate if ((err = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE, &bstats))
2880Sstevel@tonic-gate == 0) {
2890Sstevel@tonic-gate boolean_t val = (bstats != 0) ? B_TRUE : B_FALSE;
2900Sstevel@tonic-gate /* Turning on stats */
2910Sstevel@tonic-gate if (!dlcosmk_data->gather_stats && val) {
2920Sstevel@tonic-gate if ((err = dlcosmk_statinit(aid, dlcosmk_data)) != 0) {
2930Sstevel@tonic-gate nvlist_free(nvlp);
2940Sstevel@tonic-gate return (err);
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate /* Turning off stats */
2970Sstevel@tonic-gate } else if (!val && dlcosmk_data->gather_stats) {
2980Sstevel@tonic-gate ipp_stat_destroy(dlcosmk_data->stats);
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate }
3010Sstevel@tonic-gate dlcosmk_data->gather_stats = val;
3020Sstevel@tonic-gate }
3030Sstevel@tonic-gate
3040Sstevel@tonic-gate /* Free thenvlist */
3050Sstevel@tonic-gate nvlist_free(nvlp);
3060Sstevel@tonic-gate return (0);
3070Sstevel@tonic-gate }
3080Sstevel@tonic-gate
3090Sstevel@tonic-gate static int
dlcosmk_destroy_action(ipp_action_id_t aid,ipp_flags_t flags)3100Sstevel@tonic-gate dlcosmk_destroy_action(ipp_action_id_t aid, ipp_flags_t flags)
3110Sstevel@tonic-gate {
3120Sstevel@tonic-gate dlcosmk_data_t *dlcosmk_data;
3130Sstevel@tonic-gate int err;
3140Sstevel@tonic-gate
3150Sstevel@tonic-gate dlcosmk_data = (dlcosmk_data_t *)ipp_action_get_ptr(aid);
3160Sstevel@tonic-gate ASSERT(dlcosmk_data != NULL);
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate /* Destroy stats, if gathered */
3190Sstevel@tonic-gate if (dlcosmk_data->gather_stats) {
3200Sstevel@tonic-gate ipp_stat_destroy(dlcosmk_data->stats);
3210Sstevel@tonic-gate }
3220Sstevel@tonic-gate
3230Sstevel@tonic-gate /* unreference the action */
3240Sstevel@tonic-gate err = ipp_action_unref(aid, dlcosmk_data->next_action, flags);
3250Sstevel@tonic-gate ASSERT(err == 0);
3260Sstevel@tonic-gate
3270Sstevel@tonic-gate kmem_free(dlcosmk_data, DLCOSMK_DATA_SZ);
3280Sstevel@tonic-gate return (0);
3290Sstevel@tonic-gate }
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate static int
dlcosmk_invoke_action(ipp_action_id_t aid,ipp_packet_t * packet)3320Sstevel@tonic-gate dlcosmk_invoke_action(ipp_action_id_t aid, ipp_packet_t *packet)
3330Sstevel@tonic-gate {
3340Sstevel@tonic-gate dlcosmk_data_t *dlcosmk_data;
3350Sstevel@tonic-gate mblk_t *mp = NULL;
3360Sstevel@tonic-gate int err;
3370Sstevel@tonic-gate ip_priv_t *priv;
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate ASSERT(packet != NULL);
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate /* get mblk from ipp_packet structure */
3420Sstevel@tonic-gate mp = ipp_packet_get_data(packet);
3430Sstevel@tonic-gate priv = (ip_priv_t *)ipp_packet_get_private(packet);
3440Sstevel@tonic-gate
3450Sstevel@tonic-gate dlcosmk_data = (dlcosmk_data_t *)ipp_action_get_ptr(aid);
3460Sstevel@tonic-gate ASSERT(dlcosmk_data != NULL);
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate /* dlcosmk packet as configured */
3490Sstevel@tonic-gate if ((err = dlcosmk_process(&mp, dlcosmk_data, priv->ill_index,
3500Sstevel@tonic-gate priv->proc)) != 0) {
3510Sstevel@tonic-gate return (err);
3520Sstevel@tonic-gate } else {
3530Sstevel@tonic-gate /* return packet with next action set */
3540Sstevel@tonic-gate return (ipp_packet_next(packet, dlcosmk_data->next_action));
3550Sstevel@tonic-gate }
3560Sstevel@tonic-gate }
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate static int
dlcosmk_statinit(ipp_action_id_t aid,dlcosmk_data_t * dlcosmk_data)3590Sstevel@tonic-gate dlcosmk_statinit(ipp_action_id_t aid, dlcosmk_data_t *dlcosmk_data)
3600Sstevel@tonic-gate {
3610Sstevel@tonic-gate int err;
3620Sstevel@tonic-gate dlcosmk_stat_t *statp;
3630Sstevel@tonic-gate
3640Sstevel@tonic-gate /* install stats entry */
3650Sstevel@tonic-gate if ((err = ipp_stat_create(aid, DLCOSMK_STATS_STRING,
3660Sstevel@tonic-gate DLCOSMK_STATS_COUNT, dlcosmk_update_stats, dlcosmk_data,
3670Sstevel@tonic-gate &dlcosmk_data->stats)) != 0) {
3680Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_create " \
3690Sstevel@tonic-gate "returned with error %d\n", err));
3700Sstevel@tonic-gate return (err);
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate statp = (dlcosmk_stat_t *)(dlcosmk_data->stats)->ipps_data;
3740Sstevel@tonic-gate ASSERT(statp != NULL);
3750Sstevel@tonic-gate
3760Sstevel@tonic-gate if ((err = ipp_stat_named_init(dlcosmk_data->stats, "npackets",
3770Sstevel@tonic-gate IPP_STAT_UINT64, &statp->npackets)) != 0) {
3780Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
3790Sstevel@tonic-gate "returned with error %d\n", err));
3800Sstevel@tonic-gate return (err);
3810Sstevel@tonic-gate }
3820Sstevel@tonic-gate
3830Sstevel@tonic-gate if ((err = ipp_stat_named_init(dlcosmk_data->stats, "ipackets",
3840Sstevel@tonic-gate IPP_STAT_UINT64, &statp->ipackets)) != 0) {
3850Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
3860Sstevel@tonic-gate "returned with error %d\n", err));
3870Sstevel@tonic-gate return (err);
3880Sstevel@tonic-gate }
3890Sstevel@tonic-gate
3900Sstevel@tonic-gate if ((err = ipp_stat_named_init(dlcosmk_data->stats, "epackets",
3910Sstevel@tonic-gate IPP_STAT_UINT64, &statp->epackets)) != 0) {
3920Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
3930Sstevel@tonic-gate "returned with error %d\n", err));
3940Sstevel@tonic-gate return (err);
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate if ((err = ipp_stat_named_init(dlcosmk_data->stats, "usr_pri",
3980Sstevel@tonic-gate IPP_STAT_INT32, &statp->usr_pri)) != 0) {
3990Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
4000Sstevel@tonic-gate "returned with error %d", err));
4010Sstevel@tonic-gate return (err);
4020Sstevel@tonic-gate }
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate if ((err = ipp_stat_named_init(dlcosmk_data->stats, "b_band",
4050Sstevel@tonic-gate IPP_STAT_INT32, &statp->b_band)) != 0) {
4060Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
4070Sstevel@tonic-gate "returned with error %d\n", err));
4080Sstevel@tonic-gate return (err);
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate
4110Sstevel@tonic-gate if ((err = ipp_stat_named_init(dlcosmk_data->stats, "dl_max",
4120Sstevel@tonic-gate IPP_STAT_INT32, &statp->dl_max)) != 0) {
4130Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_create_action: ipp_stat_named_init " \
4140Sstevel@tonic-gate "returned with error %d\n", err));
4150Sstevel@tonic-gate return (err);
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate ipp_stat_install(dlcosmk_data->stats);
4190Sstevel@tonic-gate return (0);
4200Sstevel@tonic-gate }
4210Sstevel@tonic-gate
4220Sstevel@tonic-gate static int
dlcosmk_update_stats(ipp_stat_t * sp,void * arg,int rw)4230Sstevel@tonic-gate dlcosmk_update_stats(ipp_stat_t *sp, void *arg, int rw)
4240Sstevel@tonic-gate {
4250Sstevel@tonic-gate dlcosmk_data_t *dlcosmk_data = (dlcosmk_data_t *)arg;
4260Sstevel@tonic-gate dlcosmk_stat_t *snames = (dlcosmk_stat_t *)sp->ipps_data;
4270Sstevel@tonic-gate uint32_t upri, bband;
4280Sstevel@tonic-gate
4290Sstevel@tonic-gate ASSERT(dlcosmk_data != NULL);
4300Sstevel@tonic-gate ASSERT(snames != NULL);
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate upri = dlcosmk_data->usr_pri;
4330Sstevel@tonic-gate bband = dlcosmk_data->b_band;
4340Sstevel@tonic-gate
4350Sstevel@tonic-gate (void) ipp_stat_named_op(&snames->npackets, &dlcosmk_data->npackets,
4360Sstevel@tonic-gate rw);
4370Sstevel@tonic-gate (void) ipp_stat_named_op(&snames->ipackets, &dlcosmk_data->ipackets,
4380Sstevel@tonic-gate rw);
4390Sstevel@tonic-gate (void) ipp_stat_named_op(&snames->epackets, &dlcosmk_data->epackets,
4400Sstevel@tonic-gate rw);
4410Sstevel@tonic-gate (void) ipp_stat_named_op(&snames->usr_pri, &upri, rw);
4420Sstevel@tonic-gate (void) ipp_stat_named_op(&snames->b_band, &bband, rw);
4430Sstevel@tonic-gate (void) ipp_stat_named_op(&snames->dl_max, &dlcosmk_data->dl_max, rw);
4440Sstevel@tonic-gate
4450Sstevel@tonic-gate return (0);
4460Sstevel@tonic-gate }
4470Sstevel@tonic-gate
4480Sstevel@tonic-gate /* ARGSUSED */
4490Sstevel@tonic-gate static int
dlcosmk_info(ipp_action_id_t aid,int (* fn)(nvlist_t *,void *),void * arg,ipp_flags_t flags)4500Sstevel@tonic-gate dlcosmk_info(ipp_action_id_t aid, int (*fn)(nvlist_t *, void *), void *arg,
4510Sstevel@tonic-gate ipp_flags_t flags)
4520Sstevel@tonic-gate {
4530Sstevel@tonic-gate nvlist_t *nvlp;
4540Sstevel@tonic-gate dlcosmk_data_t *dlcosmk_data;
4550Sstevel@tonic-gate char *next_action;
4560Sstevel@tonic-gate int err;
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate ASSERT(fn != NULL);
4590Sstevel@tonic-gate
4600Sstevel@tonic-gate dlcosmk_data = (dlcosmk_data_t *)ipp_action_get_ptr(aid);
4610Sstevel@tonic-gate ASSERT(dlcosmk_data != NULL);
4620Sstevel@tonic-gate
4630Sstevel@tonic-gate /* allocate nvlist to be passed back */
4640Sstevel@tonic-gate if ((err = nvlist_alloc(&nvlp, NV_UNIQUE_NAME, KM_NOSLEEP)) != 0) {
4650Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_info: error allocating memory\n"));
4660Sstevel@tonic-gate return (err);
4670Sstevel@tonic-gate }
4680Sstevel@tonic-gate
4690Sstevel@tonic-gate /* look up next action with the next action id */
4700Sstevel@tonic-gate if ((err = ipp_action_name(dlcosmk_data->next_action,
4710Sstevel@tonic-gate &next_action)) != 0) {
4720Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_info: next action not available\n"));
4730Sstevel@tonic-gate nvlist_free(nvlp);
4740Sstevel@tonic-gate return (err);
4750Sstevel@tonic-gate }
4760Sstevel@tonic-gate
4770Sstevel@tonic-gate /* add next action name */
4780Sstevel@tonic-gate if ((err = nvlist_add_string(nvlp, DLCOSMK_NEXT_ACTION_NAME,
4790Sstevel@tonic-gate next_action)) != 0) {
4800Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_info: error adding next action\n"));
4810Sstevel@tonic-gate nvlist_free(nvlp);
4820Sstevel@tonic-gate kmem_free(next_action, (strlen(next_action) + 1));
4830Sstevel@tonic-gate return (err);
4840Sstevel@tonic-gate }
4850Sstevel@tonic-gate
4860Sstevel@tonic-gate /* free action name */
4870Sstevel@tonic-gate kmem_free(next_action, (strlen(next_action) + 1));
4880Sstevel@tonic-gate
4890Sstevel@tonic-gate /* add config type */
4900Sstevel@tonic-gate if ((err = nvlist_add_byte(nvlp, IPP_CONFIG_TYPE, IPP_SET)) != 0) {
4910Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_info: error adding config. type\n"));
4920Sstevel@tonic-gate nvlist_free(nvlp);
4930Sstevel@tonic-gate return (err);
4940Sstevel@tonic-gate }
4950Sstevel@tonic-gate
4960Sstevel@tonic-gate /* just give the cos, since that is what is provided in the config */
4970Sstevel@tonic-gate if ((err = nvlist_add_byte(nvlp, DLCOSMK_COS, dlcosmk_data->usr_pri))
4980Sstevel@tonic-gate != 0) {
4990Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_info: error adding cos\n"));
5000Sstevel@tonic-gate nvlist_free(nvlp);
5010Sstevel@tonic-gate return (err);
5020Sstevel@tonic-gate }
5030Sstevel@tonic-gate
5040Sstevel@tonic-gate /* add gather stats boolean */
5050Sstevel@tonic-gate if ((err = nvlist_add_uint32(nvlp, IPP_ACTION_STATS_ENABLE,
5060Sstevel@tonic-gate (dlcosmk_data->gather_stats ? 1 : 0))) != 0) {
5070Sstevel@tonic-gate dlcosmk0dbg(("dlcosmk_info: error adding stats status\n"));
5080Sstevel@tonic-gate nvlist_free(nvlp);
5090Sstevel@tonic-gate return (err);
5100Sstevel@tonic-gate }
5110Sstevel@tonic-gate
5120Sstevel@tonic-gate /* call back with nvlist */
5130Sstevel@tonic-gate err = fn(nvlp, arg);
5140Sstevel@tonic-gate
5150Sstevel@tonic-gate nvlist_free(nvlp);
5160Sstevel@tonic-gate return (err);
5170Sstevel@tonic-gate }
518