xref: /freebsd/sys/dev/usb/template/usb_template_cdce.c (revision d01c1c8bfecfd71ab8958ed59114fb5fb88fcdbd)
1d2b99310SHans Petter Selasky /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
3718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4718cf2ccSPedro F. Giffuni  *
55d38a4d4SEd Schouten  * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org>
68e06491aSEdward Tomasz Napierala  * Copyright (c) 2018 The FreeBSD Foundation
702ac6454SAndrew Thompson  * All rights reserved.
802ac6454SAndrew Thompson  *
98e06491aSEdward Tomasz Napierala  * Portions of this software were developed by Edward Tomasz Napierala
108e06491aSEdward Tomasz Napierala  * under sponsorship from the FreeBSD Foundation.
118e06491aSEdward Tomasz Napierala  *
1202ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
1302ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
1402ac6454SAndrew Thompson  * are met:
1502ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1602ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1702ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1802ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1902ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
2002ac6454SAndrew Thompson  *
2102ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2202ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2302ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2402ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2502ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2602ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2702ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2802ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2902ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3002ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3102ac6454SAndrew Thompson  * SUCH DAMAGE.
3202ac6454SAndrew Thompson  */
3302ac6454SAndrew Thompson 
3402ac6454SAndrew Thompson /*
3502ac6454SAndrew Thompson  * This file contains the USB templates for a CDC USB ethernet device.
3602ac6454SAndrew Thompson  */
3702ac6454SAndrew Thompson 
38d2b99310SHans Petter Selasky #ifdef USB_GLOBAL_INCLUDE_FILE
39d2b99310SHans Petter Selasky #include USB_GLOBAL_INCLUDE_FILE
40d2b99310SHans Petter Selasky #else
41ed6d949aSAndrew Thompson #include <sys/stdint.h>
42ed6d949aSAndrew Thompson #include <sys/stddef.h>
43ed6d949aSAndrew Thompson #include <sys/param.h>
44ed6d949aSAndrew Thompson #include <sys/queue.h>
45ed6d949aSAndrew Thompson #include <sys/types.h>
46ed6d949aSAndrew Thompson #include <sys/systm.h>
47ed6d949aSAndrew Thompson #include <sys/kernel.h>
48ed6d949aSAndrew Thompson #include <sys/bus.h>
49ed6d949aSAndrew Thompson #include <sys/module.h>
50ed6d949aSAndrew Thompson #include <sys/lock.h>
51ed6d949aSAndrew Thompson #include <sys/mutex.h>
52ed6d949aSAndrew Thompson #include <sys/condvar.h>
53ed6d949aSAndrew Thompson #include <sys/sysctl.h>
54ed6d949aSAndrew Thompson #include <sys/sx.h>
55ed6d949aSAndrew Thompson #include <sys/unistd.h>
56ed6d949aSAndrew Thompson #include <sys/callout.h>
57ed6d949aSAndrew Thompson #include <sys/malloc.h>
58ed6d949aSAndrew Thompson #include <sys/priv.h>
5902ac6454SAndrew Thompson 
60ed6d949aSAndrew Thompson #include <dev/usb/usb.h>
61ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h>
6223ab0871SHans Petter Selasky #include <dev/usb/usb_core.h>
63ed6d949aSAndrew Thompson #include <dev/usb/usb_cdc.h>
648e06491aSEdward Tomasz Napierala #include <dev/usb/usb_ioctl.h>
658e06491aSEdward Tomasz Napierala #include <dev/usb/usb_util.h>
6602ac6454SAndrew Thompson 
6702ac6454SAndrew Thompson #include <dev/usb/template/usb_template.h>
68d2b99310SHans Petter Selasky #endif			/* USB_GLOBAL_INCLUDE_FILE */
6902ac6454SAndrew Thompson 
7002ac6454SAndrew Thompson enum {
718e06491aSEdward Tomasz Napierala 	ETH_LANG_INDEX,
728e06491aSEdward Tomasz Napierala 	ETH_MAC_INDEX,
738e06491aSEdward Tomasz Napierala 	ETH_CONTROL_INDEX,
748e06491aSEdward Tomasz Napierala 	ETH_DATA_INDEX,
758e06491aSEdward Tomasz Napierala 	ETH_CONFIGURATION_INDEX,
768e06491aSEdward Tomasz Napierala 	ETH_MANUFACTURER_INDEX,
778e06491aSEdward Tomasz Napierala 	ETH_PRODUCT_INDEX,
788e06491aSEdward Tomasz Napierala 	ETH_SERIAL_NUMBER_INDEX,
798e06491aSEdward Tomasz Napierala 	ETH_MAX_INDEX,
8002ac6454SAndrew Thompson };
8102ac6454SAndrew Thompson 
821558eec6SEdward Tomasz Napierala #define	ETH_DEFAULT_VENDOR_ID		USB_TEMPLATE_VENDOR
83*d01c1c8bSEdward Tomasz Napierala #define	ETH_DEFAULT_PRODUCT_ID		0x05dc
848e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_MAC			"2A02030405060789AB"
858e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_CONTROL		"USB Ethernet Comm Interface"
868e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_DATA		"USB Ethernet Data Interface"
878e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_CONFIG		"Default Config"
88*d01c1c8bSEdward Tomasz Napierala #define	ETH_DEFAULT_MANUFACTURER	USB_TEMPLATE_MANUFACTURER
898e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_PRODUCT		"USB Ethernet Adapter"
908e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_SERIAL_NUMBER	"December 2007"
9102ac6454SAndrew Thompson 
928e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_mac;
938e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_control;
948e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_data;
958e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_configuration;
968e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_manufacturer;
978e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_product;
988e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_serial_number;
9902ac6454SAndrew Thompson 
1008e06491aSEdward Tomasz Napierala static struct sysctl_ctx_list		eth_ctx_list;
10102ac6454SAndrew Thompson 
10202ac6454SAndrew Thompson /* prototypes */
10302ac6454SAndrew Thompson 
104a593f6b8SAndrew Thompson static usb_temp_get_string_desc_t eth_get_string_desc;
10502ac6454SAndrew Thompson 
106760bc48eSAndrew Thompson static const struct usb_cdc_union_descriptor eth_union_desc = {
10702ac6454SAndrew Thompson 	.bLength = sizeof(eth_union_desc),
10802ac6454SAndrew Thompson 	.bDescriptorType = UDESC_CS_INTERFACE,
10902ac6454SAndrew Thompson 	.bDescriptorSubtype = UDESCSUB_CDC_UNION,
11002ac6454SAndrew Thompson 	.bMasterInterface = 0,		/* this is automatically updated */
11102ac6454SAndrew Thompson 	.bSlaveInterface[0] = 1,	/* this is automatically updated */
11202ac6454SAndrew Thompson };
11302ac6454SAndrew Thompson 
114760bc48eSAndrew Thompson static const struct usb_cdc_header_descriptor eth_header_desc = {
11502ac6454SAndrew Thompson 	.bLength = sizeof(eth_header_desc),
11602ac6454SAndrew Thompson 	.bDescriptorType = UDESC_CS_INTERFACE,
11702ac6454SAndrew Thompson 	.bDescriptorSubtype = UDESCSUB_CDC_HEADER,
11802ac6454SAndrew Thompson 	.bcdCDC[0] = 0x10,
11902ac6454SAndrew Thompson 	.bcdCDC[1] = 0x01,
12002ac6454SAndrew Thompson };
12102ac6454SAndrew Thompson 
122760bc48eSAndrew Thompson static const struct usb_cdc_ethernet_descriptor eth_enf_desc = {
12302ac6454SAndrew Thompson 	.bLength = sizeof(eth_enf_desc),
12402ac6454SAndrew Thompson 	.bDescriptorType = UDESC_CS_INTERFACE,
12502ac6454SAndrew Thompson 	.bDescriptorSubtype = UDESCSUB_CDC_ENF,
1268e06491aSEdward Tomasz Napierala 	.iMacAddress = ETH_MAC_INDEX,
12702ac6454SAndrew Thompson 	.bmEthernetStatistics = {0, 0, 0, 0},
12802ac6454SAndrew Thompson 	.wMaxSegmentSize = {0xEA, 0x05},/* 1514 bytes */
12902ac6454SAndrew Thompson 	.wNumberMCFilters = {0, 0},
13002ac6454SAndrew Thompson 	.bNumberPowerFilters = 0,
13102ac6454SAndrew Thompson };
13202ac6454SAndrew Thompson 
13302ac6454SAndrew Thompson static const void *eth_control_if_desc[] = {
13402ac6454SAndrew Thompson 	&eth_union_desc,
13502ac6454SAndrew Thompson 	&eth_header_desc,
13602ac6454SAndrew Thompson 	&eth_enf_desc,
13702ac6454SAndrew Thompson 	NULL,
13802ac6454SAndrew Thompson };
13902ac6454SAndrew Thompson 
140760bc48eSAndrew Thompson static const struct usb_temp_packet_size bulk_mps = {
14102ac6454SAndrew Thompson 	.mps[USB_SPEED_FULL] = 64,
14202ac6454SAndrew Thompson 	.mps[USB_SPEED_HIGH] = 512,
14302ac6454SAndrew Thompson };
14402ac6454SAndrew Thompson 
145760bc48eSAndrew Thompson static const struct usb_temp_packet_size intr_mps = {
14602ac6454SAndrew Thompson 	.mps[USB_SPEED_FULL] = 8,
14702ac6454SAndrew Thompson 	.mps[USB_SPEED_HIGH] = 8,
14802ac6454SAndrew Thompson };
14902ac6454SAndrew Thompson 
150760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc bulk_in_ep = {
15102ac6454SAndrew Thompson 	.pPacketSize = &bulk_mps,
15202ac6454SAndrew Thompson #ifdef USB_HIP_IN_EP_0
15302ac6454SAndrew Thompson 	.bEndpointAddress = USB_HIP_IN_EP_0,
15402ac6454SAndrew Thompson #else
15502ac6454SAndrew Thompson 	.bEndpointAddress = UE_DIR_IN,
15602ac6454SAndrew Thompson #endif
15702ac6454SAndrew Thompson 	.bmAttributes = UE_BULK,
15802ac6454SAndrew Thompson };
15902ac6454SAndrew Thompson 
160760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc bulk_out_ep = {
16102ac6454SAndrew Thompson 	.pPacketSize = &bulk_mps,
16202ac6454SAndrew Thompson #ifdef USB_HIP_OUT_EP_0
16302ac6454SAndrew Thompson 	.bEndpointAddress = USB_HIP_OUT_EP_0,
16402ac6454SAndrew Thompson #else
16502ac6454SAndrew Thompson 	.bEndpointAddress = UE_DIR_OUT,
16602ac6454SAndrew Thompson #endif
16702ac6454SAndrew Thompson 	.bmAttributes = UE_BULK,
16802ac6454SAndrew Thompson };
16902ac6454SAndrew Thompson 
170760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc intr_in_ep = {
17102ac6454SAndrew Thompson 	.pPacketSize = &intr_mps,
17202ac6454SAndrew Thompson 	.bEndpointAddress = UE_DIR_IN,
17302ac6454SAndrew Thompson 	.bmAttributes = UE_INTERRUPT,
17402ac6454SAndrew Thompson };
17502ac6454SAndrew Thompson 
176760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc *eth_intr_endpoints[] = {
17702ac6454SAndrew Thompson 	&intr_in_ep,
17802ac6454SAndrew Thompson 	NULL,
17902ac6454SAndrew Thompson };
18002ac6454SAndrew Thompson 
181760bc48eSAndrew Thompson static const struct usb_temp_interface_desc eth_control_interface = {
18202ac6454SAndrew Thompson 	.ppEndpoints = eth_intr_endpoints,
18302ac6454SAndrew Thompson 	.ppRawDesc = eth_control_if_desc,
18402ac6454SAndrew Thompson 	.bInterfaceClass = UICLASS_CDC,
18502ac6454SAndrew Thompson 	.bInterfaceSubClass = UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL,
18602ac6454SAndrew Thompson 	.bInterfaceProtocol = 0,
1878e06491aSEdward Tomasz Napierala 	.iInterface = ETH_CONTROL_INDEX,
18802ac6454SAndrew Thompson };
18902ac6454SAndrew Thompson 
190760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc *eth_data_endpoints[] = {
19102ac6454SAndrew Thompson 	&bulk_in_ep,
19202ac6454SAndrew Thompson 	&bulk_out_ep,
19302ac6454SAndrew Thompson 	NULL,
19402ac6454SAndrew Thompson };
19502ac6454SAndrew Thompson 
196760bc48eSAndrew Thompson static const struct usb_temp_interface_desc eth_data_null_interface = {
19702ac6454SAndrew Thompson 	.ppEndpoints = NULL,		/* no endpoints */
19802ac6454SAndrew Thompson 	.bInterfaceClass = UICLASS_CDC_DATA,
19902ac6454SAndrew Thompson 	.bInterfaceSubClass = 0,
20002ac6454SAndrew Thompson 	.bInterfaceProtocol = 0,
2018e06491aSEdward Tomasz Napierala 	.iInterface = ETH_DATA_INDEX,
20202ac6454SAndrew Thompson };
20302ac6454SAndrew Thompson 
204760bc48eSAndrew Thompson static const struct usb_temp_interface_desc eth_data_interface = {
20502ac6454SAndrew Thompson 	.ppEndpoints = eth_data_endpoints,
20602ac6454SAndrew Thompson 	.bInterfaceClass = UICLASS_CDC_DATA,
20702ac6454SAndrew Thompson 	.bInterfaceSubClass = UISUBCLASS_DATA,
20802ac6454SAndrew Thompson 	.bInterfaceProtocol = 0,
2098e06491aSEdward Tomasz Napierala 	.iInterface = ETH_DATA_INDEX,
21002ac6454SAndrew Thompson 	.isAltInterface = 1,		/* this is an alternate setting */
21102ac6454SAndrew Thompson };
21202ac6454SAndrew Thompson 
213760bc48eSAndrew Thompson static const struct usb_temp_interface_desc *eth_interfaces[] = {
21402ac6454SAndrew Thompson 	&eth_control_interface,
21502ac6454SAndrew Thompson 	&eth_data_null_interface,
21602ac6454SAndrew Thompson 	&eth_data_interface,
21702ac6454SAndrew Thompson 	NULL,
21802ac6454SAndrew Thompson };
21902ac6454SAndrew Thompson 
220760bc48eSAndrew Thompson static const struct usb_temp_config_desc eth_config_desc = {
22102ac6454SAndrew Thompson 	.ppIfaceDesc = eth_interfaces,
22202ac6454SAndrew Thompson 	.bmAttributes = UC_BUS_POWERED,
22302ac6454SAndrew Thompson 	.bMaxPower = 25,		/* 50 mA */
2248e06491aSEdward Tomasz Napierala 	.iConfiguration = ETH_CONFIGURATION_INDEX,
22502ac6454SAndrew Thompson };
22602ac6454SAndrew Thompson 
227760bc48eSAndrew Thompson static const struct usb_temp_config_desc *eth_configs[] = {
22802ac6454SAndrew Thompson 	&eth_config_desc,
22902ac6454SAndrew Thompson 	NULL,
23002ac6454SAndrew Thompson };
23102ac6454SAndrew Thompson 
2328e06491aSEdward Tomasz Napierala struct usb_temp_device_desc usb_template_cdce = {
23302ac6454SAndrew Thompson 	.getStringDesc = &eth_get_string_desc,
23402ac6454SAndrew Thompson 	.ppConfigDesc = eth_configs,
2351558eec6SEdward Tomasz Napierala 	.idVendor = ETH_DEFAULT_VENDOR_ID,
2361558eec6SEdward Tomasz Napierala 	.idProduct = ETH_DEFAULT_PRODUCT_ID,
23702ac6454SAndrew Thompson 	.bcdDevice = 0x0100,
23802ac6454SAndrew Thompson 	.bDeviceClass = UDCLASS_COMM,
23902ac6454SAndrew Thompson 	.bDeviceSubClass = 0,
24002ac6454SAndrew Thompson 	.bDeviceProtocol = 0,
2418e06491aSEdward Tomasz Napierala 	.iManufacturer = ETH_MANUFACTURER_INDEX,
2428e06491aSEdward Tomasz Napierala 	.iProduct = ETH_PRODUCT_INDEX,
2438e06491aSEdward Tomasz Napierala 	.iSerialNumber = ETH_SERIAL_NUMBER_INDEX,
24402ac6454SAndrew Thompson };
24502ac6454SAndrew Thompson 
24602ac6454SAndrew Thompson /*------------------------------------------------------------------------*
24702ac6454SAndrew Thompson  *	eth_get_string_desc
24802ac6454SAndrew Thompson  *
24902ac6454SAndrew Thompson  * Return values:
25002ac6454SAndrew Thompson  * NULL: Failure. No such string.
25102ac6454SAndrew Thompson  * Else: Success. Pointer to string descriptor is returned.
25202ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
25302ac6454SAndrew Thompson static const void *
25402ac6454SAndrew Thompson eth_get_string_desc(uint16_t lang_id, uint8_t string_index)
25502ac6454SAndrew Thompson {
2568e06491aSEdward Tomasz Napierala 	static const void *ptr[ETH_MAX_INDEX] = {
2578e06491aSEdward Tomasz Napierala 		[ETH_LANG_INDEX] = &usb_string_lang_en,
2588e06491aSEdward Tomasz Napierala 		[ETH_MAC_INDEX] = &eth_mac,
2598e06491aSEdward Tomasz Napierala 		[ETH_CONTROL_INDEX] = &eth_control,
2608e06491aSEdward Tomasz Napierala 		[ETH_DATA_INDEX] = &eth_data,
2618e06491aSEdward Tomasz Napierala 		[ETH_CONFIGURATION_INDEX] = &eth_configuration,
2628e06491aSEdward Tomasz Napierala 		[ETH_MANUFACTURER_INDEX] = &eth_manufacturer,
2638e06491aSEdward Tomasz Napierala 		[ETH_PRODUCT_INDEX] = &eth_product,
2648e06491aSEdward Tomasz Napierala 		[ETH_SERIAL_NUMBER_INDEX] = &eth_serial_number,
26502ac6454SAndrew Thompson 	};
26602ac6454SAndrew Thompson 
26702ac6454SAndrew Thompson 	if (string_index == 0) {
26823ab0871SHans Petter Selasky 		return (&usb_string_lang_en);
26902ac6454SAndrew Thompson 	}
27002ac6454SAndrew Thompson 	if (lang_id != 0x0409) {
27102ac6454SAndrew Thompson 		return (NULL);
27202ac6454SAndrew Thompson 	}
2738e06491aSEdward Tomasz Napierala 	if (string_index < ETH_MAX_INDEX) {
27402ac6454SAndrew Thompson 		return (ptr[string_index]);
27502ac6454SAndrew Thompson 	}
27602ac6454SAndrew Thompson 	return (NULL);
27702ac6454SAndrew Thompson }
2788e06491aSEdward Tomasz Napierala 
2798e06491aSEdward Tomasz Napierala static void
2808e06491aSEdward Tomasz Napierala eth_init(void *arg __unused)
2818e06491aSEdward Tomasz Napierala {
2828e06491aSEdward Tomasz Napierala 	struct sysctl_oid *parent;
2838e06491aSEdward Tomasz Napierala 	char parent_name[3];
2848e06491aSEdward Tomasz Napierala 
2858e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_mac, sizeof(eth_mac),
2868e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_MAC);
2878e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_control, sizeof(eth_control),
2888e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_CONTROL);
2898e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_data, sizeof(eth_data),
2908e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_DATA);
2918e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_configuration, sizeof(eth_configuration),
2928e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_CONFIG);
2938e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_manufacturer, sizeof(eth_manufacturer),
2948e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_MANUFACTURER);
2958e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_product, sizeof(eth_product),
2968e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_PRODUCT);
2978e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_serial_number, sizeof(eth_serial_number),
2988e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_SERIAL_NUMBER);
2998e06491aSEdward Tomasz Napierala 
3008e06491aSEdward Tomasz Napierala 	snprintf(parent_name, sizeof(parent_name), "%d", USB_TEMP_CDCE);
3018e06491aSEdward Tomasz Napierala 	sysctl_ctx_init(&eth_ctx_list);
3028e06491aSEdward Tomasz Napierala 
3038e06491aSEdward Tomasz Napierala 	parent = SYSCTL_ADD_NODE(&eth_ctx_list,
3048e06491aSEdward Tomasz Napierala 	    SYSCTL_STATIC_CHILDREN(_hw_usb_templates), OID_AUTO,
3058e06491aSEdward Tomasz Napierala 	    parent_name, CTLFLAG_RW,
3068e06491aSEdward Tomasz Napierala 	    0, "USB CDC Ethernet device side template");
3078e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_U16(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3088e06491aSEdward Tomasz Napierala 	    "vendor_id", CTLFLAG_RWTUN,
3098e06491aSEdward Tomasz Napierala 	    &usb_template_cdce.idVendor, 1, "Vendor identifier");
3108e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_U16(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3118e06491aSEdward Tomasz Napierala 	    "product_id", CTLFLAG_RWTUN,
3128e06491aSEdward Tomasz Napierala 	    &usb_template_cdce.idProduct, 1, "Product identifier");
3138e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3148e06491aSEdward Tomasz Napierala 	    "mac", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3158e06491aSEdward Tomasz Napierala 	    &eth_mac, sizeof(eth_mac), usb_temp_sysctl,
3168e06491aSEdward Tomasz Napierala 	    "A", "MAC address string");
3178e06491aSEdward Tomasz Napierala #if 0
3188e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3198e06491aSEdward Tomasz Napierala 	    "control", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3208e06491aSEdward Tomasz Napierala 	    &eth_control, sizeof(eth_control), usb_temp_sysctl,
3218e06491aSEdward Tomasz Napierala 	    "A", "Control interface string");
3228e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3238e06491aSEdward Tomasz Napierala 	    "data", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3248e06491aSEdward Tomasz Napierala 	    &eth_data, sizeof(eth_data), usb_temp_sysctl,
3258e06491aSEdward Tomasz Napierala 	    "A", "Data interface string");
3268e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3278e06491aSEdward Tomasz Napierala 	    "configuration", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3288e06491aSEdward Tomasz Napierala 	    &eth_configuration, sizeof(eth_configuration), usb_temp_sysctl,
3298e06491aSEdward Tomasz Napierala 	    "A", "Configuration string");
3308e06491aSEdward Tomasz Napierala #endif
3318e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3328e06491aSEdward Tomasz Napierala 	    "manufacturer", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3338e06491aSEdward Tomasz Napierala 	    &eth_manufacturer, sizeof(eth_manufacturer), usb_temp_sysctl,
3348e06491aSEdward Tomasz Napierala 	    "A", "Manufacturer string");
3358e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3368e06491aSEdward Tomasz Napierala 	    "product", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3378e06491aSEdward Tomasz Napierala 	    &eth_product, sizeof(eth_product), usb_temp_sysctl,
3388e06491aSEdward Tomasz Napierala 	    "A", "Product string");
3398e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3408e06491aSEdward Tomasz Napierala 	    "serial_number", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3418e06491aSEdward Tomasz Napierala 	    &eth_serial_number, sizeof(eth_serial_number), usb_temp_sysctl,
3428e06491aSEdward Tomasz Napierala 	    "A", "Serial number string");
3438e06491aSEdward Tomasz Napierala }
3448e06491aSEdward Tomasz Napierala 
3458e06491aSEdward Tomasz Napierala static void
3468e06491aSEdward Tomasz Napierala eth_uninit(void *arg __unused)
3478e06491aSEdward Tomasz Napierala {
3488e06491aSEdward Tomasz Napierala 
3498e06491aSEdward Tomasz Napierala 	sysctl_ctx_free(&eth_ctx_list);
3508e06491aSEdward Tomasz Napierala }
3518e06491aSEdward Tomasz Napierala 
3528e06491aSEdward Tomasz Napierala SYSINIT(eth_init, SI_SUB_LOCK, SI_ORDER_FIRST, eth_init, NULL);
353c70e38e4SHans Petter Selasky SYSUNINIT(eth_uninit, SI_SUB_LOCK, SI_ORDER_FIRST, eth_uninit, NULL);
354