xref: /freebsd/sys/dev/usb/template/usb_template_cdce.c (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
102ac6454SAndrew Thompson /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
45d38a4d4SEd Schouten  * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org>
58e06491aSEdward Tomasz Napierala  * Copyright (c) 2018 The FreeBSD Foundation
602ac6454SAndrew Thompson  * All rights reserved.
702ac6454SAndrew Thompson  *
88e06491aSEdward Tomasz Napierala  * Portions of this software were developed by Edward Tomasz Napierala
98e06491aSEdward Tomasz Napierala  * under sponsorship from the FreeBSD Foundation.
108e06491aSEdward Tomasz Napierala  *
1102ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
1202ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
1302ac6454SAndrew Thompson  * are met:
1402ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1502ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1602ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1702ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1802ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1902ac6454SAndrew Thompson  *
2002ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2102ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2202ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2302ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2402ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2502ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2602ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2702ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2802ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2902ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3002ac6454SAndrew Thompson  * SUCH DAMAGE.
3102ac6454SAndrew Thompson  */
3202ac6454SAndrew Thompson 
3302ac6454SAndrew Thompson /*
3402ac6454SAndrew Thompson  * This file contains the USB templates for a CDC USB ethernet device.
3502ac6454SAndrew Thompson  */
3602ac6454SAndrew Thompson 
37d2b99310SHans Petter Selasky #ifdef USB_GLOBAL_INCLUDE_FILE
38d2b99310SHans Petter Selasky #include USB_GLOBAL_INCLUDE_FILE
39d2b99310SHans Petter Selasky #else
40ed6d949aSAndrew Thompson #include <sys/stdint.h>
41ed6d949aSAndrew Thompson #include <sys/stddef.h>
42ed6d949aSAndrew Thompson #include <sys/param.h>
43ed6d949aSAndrew Thompson #include <sys/queue.h>
44ed6d949aSAndrew Thompson #include <sys/types.h>
45ed6d949aSAndrew Thompson #include <sys/systm.h>
46ed6d949aSAndrew Thompson #include <sys/kernel.h>
47ed6d949aSAndrew Thompson #include <sys/bus.h>
48ed6d949aSAndrew Thompson #include <sys/module.h>
49ed6d949aSAndrew Thompson #include <sys/lock.h>
50ed6d949aSAndrew Thompson #include <sys/mutex.h>
51ed6d949aSAndrew Thompson #include <sys/condvar.h>
52ed6d949aSAndrew Thompson #include <sys/sysctl.h>
53ed6d949aSAndrew Thompson #include <sys/sx.h>
54ed6d949aSAndrew Thompson #include <sys/unistd.h>
55ed6d949aSAndrew Thompson #include <sys/callout.h>
56ed6d949aSAndrew Thompson #include <sys/malloc.h>
57ed6d949aSAndrew Thompson #include <sys/priv.h>
5802ac6454SAndrew Thompson 
59ed6d949aSAndrew Thompson #include <dev/usb/usb.h>
60ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h>
6123ab0871SHans Petter Selasky #include <dev/usb/usb_core.h>
62ed6d949aSAndrew Thompson #include <dev/usb/usb_cdc.h>
638e06491aSEdward Tomasz Napierala #include <dev/usb/usb_ioctl.h>
648e06491aSEdward Tomasz Napierala #include <dev/usb/usb_util.h>
6502ac6454SAndrew Thompson 
6602ac6454SAndrew Thompson #include <dev/usb/template/usb_template.h>
67d2b99310SHans Petter Selasky #endif			/* USB_GLOBAL_INCLUDE_FILE */
6802ac6454SAndrew Thompson 
6902ac6454SAndrew Thompson enum {
708e06491aSEdward Tomasz Napierala 	ETH_LANG_INDEX,
718e06491aSEdward Tomasz Napierala 	ETH_MAC_INDEX,
728e06491aSEdward Tomasz Napierala 	ETH_CONTROL_INDEX,
738e06491aSEdward Tomasz Napierala 	ETH_DATA_INDEX,
748e06491aSEdward Tomasz Napierala 	ETH_CONFIGURATION_INDEX,
758e06491aSEdward Tomasz Napierala 	ETH_MANUFACTURER_INDEX,
768e06491aSEdward Tomasz Napierala 	ETH_PRODUCT_INDEX,
778e06491aSEdward Tomasz Napierala 	ETH_SERIAL_NUMBER_INDEX,
788e06491aSEdward Tomasz Napierala 	ETH_MAX_INDEX,
7902ac6454SAndrew Thompson };
8002ac6454SAndrew Thompson 
811558eec6SEdward Tomasz Napierala #define	ETH_DEFAULT_VENDOR_ID		USB_TEMPLATE_VENDOR
82defd918dSEdward Tomasz Napierala #define	ETH_DEFAULT_PRODUCT_ID		0x27e1
838e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_MAC			"2A02030405060789AB"
848e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_CONTROL		"USB Ethernet Comm Interface"
858e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_DATA		"USB Ethernet Data Interface"
868e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_CONFIG		"Default Config"
87d01c1c8bSEdward Tomasz Napierala #define	ETH_DEFAULT_MANUFACTURER	USB_TEMPLATE_MANUFACTURER
888e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_PRODUCT		"USB Ethernet Adapter"
898e06491aSEdward Tomasz Napierala #define	ETH_DEFAULT_SERIAL_NUMBER	"December 2007"
9002ac6454SAndrew Thompson 
918e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_mac;
928e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_control;
938e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_data;
948e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_configuration;
958e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_manufacturer;
968e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_product;
978e06491aSEdward Tomasz Napierala static struct usb_string_descriptor	eth_serial_number;
9802ac6454SAndrew Thompson 
998e06491aSEdward Tomasz Napierala static struct sysctl_ctx_list		eth_ctx_list;
10002ac6454SAndrew Thompson 
10102ac6454SAndrew Thompson /* prototypes */
10202ac6454SAndrew Thompson 
103a593f6b8SAndrew Thompson static usb_temp_get_string_desc_t eth_get_string_desc;
10402ac6454SAndrew Thompson 
105760bc48eSAndrew Thompson static const struct usb_cdc_union_descriptor eth_union_desc = {
10602ac6454SAndrew Thompson 	.bLength = sizeof(eth_union_desc),
10702ac6454SAndrew Thompson 	.bDescriptorType = UDESC_CS_INTERFACE,
10802ac6454SAndrew Thompson 	.bDescriptorSubtype = UDESCSUB_CDC_UNION,
10902ac6454SAndrew Thompson 	.bMasterInterface = 0,		/* this is automatically updated */
11002ac6454SAndrew Thompson 	.bSlaveInterface[0] = 1,	/* this is automatically updated */
11102ac6454SAndrew Thompson };
11202ac6454SAndrew Thompson 
113760bc48eSAndrew Thompson static const struct usb_cdc_header_descriptor eth_header_desc = {
11402ac6454SAndrew Thompson 	.bLength = sizeof(eth_header_desc),
11502ac6454SAndrew Thompson 	.bDescriptorType = UDESC_CS_INTERFACE,
11602ac6454SAndrew Thompson 	.bDescriptorSubtype = UDESCSUB_CDC_HEADER,
11702ac6454SAndrew Thompson 	.bcdCDC[0] = 0x10,
11802ac6454SAndrew Thompson 	.bcdCDC[1] = 0x01,
11902ac6454SAndrew Thompson };
12002ac6454SAndrew Thompson 
121760bc48eSAndrew Thompson static const struct usb_cdc_ethernet_descriptor eth_enf_desc = {
12202ac6454SAndrew Thompson 	.bLength = sizeof(eth_enf_desc),
12302ac6454SAndrew Thompson 	.bDescriptorType = UDESC_CS_INTERFACE,
12402ac6454SAndrew Thompson 	.bDescriptorSubtype = UDESCSUB_CDC_ENF,
1258e06491aSEdward Tomasz Napierala 	.iMacAddress = ETH_MAC_INDEX,
12602ac6454SAndrew Thompson 	.bmEthernetStatistics = {0, 0, 0, 0},
12702ac6454SAndrew Thompson 	.wMaxSegmentSize = {0xEA, 0x05},/* 1514 bytes */
12802ac6454SAndrew Thompson 	.wNumberMCFilters = {0, 0},
12902ac6454SAndrew Thompson 	.bNumberPowerFilters = 0,
13002ac6454SAndrew Thompson };
13102ac6454SAndrew Thompson 
13202ac6454SAndrew Thompson static const void *eth_control_if_desc[] = {
13302ac6454SAndrew Thompson 	&eth_union_desc,
13402ac6454SAndrew Thompson 	&eth_header_desc,
13502ac6454SAndrew Thompson 	&eth_enf_desc,
13602ac6454SAndrew Thompson 	NULL,
13702ac6454SAndrew Thompson };
13802ac6454SAndrew Thompson 
139760bc48eSAndrew Thompson static const struct usb_temp_packet_size bulk_mps = {
14002ac6454SAndrew Thompson 	.mps[USB_SPEED_FULL] = 64,
14102ac6454SAndrew Thompson 	.mps[USB_SPEED_HIGH] = 512,
14202ac6454SAndrew Thompson };
14302ac6454SAndrew Thompson 
144760bc48eSAndrew Thompson static const struct usb_temp_packet_size intr_mps = {
14502ac6454SAndrew Thompson 	.mps[USB_SPEED_FULL] = 8,
14602ac6454SAndrew Thompson 	.mps[USB_SPEED_HIGH] = 8,
14702ac6454SAndrew Thompson };
14802ac6454SAndrew Thompson 
149760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc bulk_in_ep = {
15002ac6454SAndrew Thompson 	.pPacketSize = &bulk_mps,
15102ac6454SAndrew Thompson #ifdef USB_HIP_IN_EP_0
15202ac6454SAndrew Thompson 	.bEndpointAddress = USB_HIP_IN_EP_0,
15302ac6454SAndrew Thompson #else
15402ac6454SAndrew Thompson 	.bEndpointAddress = UE_DIR_IN,
15502ac6454SAndrew Thompson #endif
15602ac6454SAndrew Thompson 	.bmAttributes = UE_BULK,
15702ac6454SAndrew Thompson };
15802ac6454SAndrew Thompson 
159760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc bulk_out_ep = {
16002ac6454SAndrew Thompson 	.pPacketSize = &bulk_mps,
16102ac6454SAndrew Thompson #ifdef USB_HIP_OUT_EP_0
16202ac6454SAndrew Thompson 	.bEndpointAddress = USB_HIP_OUT_EP_0,
16302ac6454SAndrew Thompson #else
16402ac6454SAndrew Thompson 	.bEndpointAddress = UE_DIR_OUT,
16502ac6454SAndrew Thompson #endif
16602ac6454SAndrew Thompson 	.bmAttributes = UE_BULK,
16702ac6454SAndrew Thompson };
16802ac6454SAndrew Thompson 
169760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc intr_in_ep = {
17002ac6454SAndrew Thompson 	.pPacketSize = &intr_mps,
17102ac6454SAndrew Thompson 	.bEndpointAddress = UE_DIR_IN,
17202ac6454SAndrew Thompson 	.bmAttributes = UE_INTERRUPT,
17302ac6454SAndrew Thompson };
17402ac6454SAndrew Thompson 
175760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc *eth_intr_endpoints[] = {
17602ac6454SAndrew Thompson 	&intr_in_ep,
17702ac6454SAndrew Thompson 	NULL,
17802ac6454SAndrew Thompson };
17902ac6454SAndrew Thompson 
180760bc48eSAndrew Thompson static const struct usb_temp_interface_desc eth_control_interface = {
18102ac6454SAndrew Thompson 	.ppEndpoints = eth_intr_endpoints,
18202ac6454SAndrew Thompson 	.ppRawDesc = eth_control_if_desc,
18302ac6454SAndrew Thompson 	.bInterfaceClass = UICLASS_CDC,
18402ac6454SAndrew Thompson 	.bInterfaceSubClass = UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL,
18502ac6454SAndrew Thompson 	.bInterfaceProtocol = 0,
1868e06491aSEdward Tomasz Napierala 	.iInterface = ETH_CONTROL_INDEX,
18702ac6454SAndrew Thompson };
18802ac6454SAndrew Thompson 
189760bc48eSAndrew Thompson static const struct usb_temp_endpoint_desc *eth_data_endpoints[] = {
19002ac6454SAndrew Thompson 	&bulk_in_ep,
19102ac6454SAndrew Thompson 	&bulk_out_ep,
19202ac6454SAndrew Thompson 	NULL,
19302ac6454SAndrew Thompson };
19402ac6454SAndrew Thompson 
195760bc48eSAndrew Thompson static const struct usb_temp_interface_desc eth_data_null_interface = {
19602ac6454SAndrew Thompson 	.ppEndpoints = NULL,		/* no endpoints */
19702ac6454SAndrew Thompson 	.bInterfaceClass = UICLASS_CDC_DATA,
19802ac6454SAndrew Thompson 	.bInterfaceSubClass = 0,
19902ac6454SAndrew Thompson 	.bInterfaceProtocol = 0,
2008e06491aSEdward Tomasz Napierala 	.iInterface = ETH_DATA_INDEX,
20102ac6454SAndrew Thompson };
20202ac6454SAndrew Thompson 
203760bc48eSAndrew Thompson static const struct usb_temp_interface_desc eth_data_interface = {
20402ac6454SAndrew Thompson 	.ppEndpoints = eth_data_endpoints,
20502ac6454SAndrew Thompson 	.bInterfaceClass = UICLASS_CDC_DATA,
20602ac6454SAndrew Thompson 	.bInterfaceSubClass = UISUBCLASS_DATA,
20702ac6454SAndrew Thompson 	.bInterfaceProtocol = 0,
2088e06491aSEdward Tomasz Napierala 	.iInterface = ETH_DATA_INDEX,
20902ac6454SAndrew Thompson 	.isAltInterface = 1,		/* this is an alternate setting */
21002ac6454SAndrew Thompson };
21102ac6454SAndrew Thompson 
212760bc48eSAndrew Thompson static const struct usb_temp_interface_desc *eth_interfaces[] = {
21302ac6454SAndrew Thompson 	&eth_control_interface,
21402ac6454SAndrew Thompson 	&eth_data_null_interface,
21502ac6454SAndrew Thompson 	&eth_data_interface,
21602ac6454SAndrew Thompson 	NULL,
21702ac6454SAndrew Thompson };
21802ac6454SAndrew Thompson 
219760bc48eSAndrew Thompson static const struct usb_temp_config_desc eth_config_desc = {
22002ac6454SAndrew Thompson 	.ppIfaceDesc = eth_interfaces,
221d008c0d7SEdward Tomasz Napierala 	.bmAttributes = 0,
222d008c0d7SEdward Tomasz Napierala 	.bMaxPower = 0,
2238e06491aSEdward Tomasz Napierala 	.iConfiguration = ETH_CONFIGURATION_INDEX,
22402ac6454SAndrew Thompson };
22502ac6454SAndrew Thompson 
226760bc48eSAndrew Thompson static const struct usb_temp_config_desc *eth_configs[] = {
22702ac6454SAndrew Thompson 	&eth_config_desc,
22802ac6454SAndrew Thompson 	NULL,
22902ac6454SAndrew Thompson };
23002ac6454SAndrew Thompson 
2318e06491aSEdward Tomasz Napierala struct usb_temp_device_desc usb_template_cdce = {
23202ac6454SAndrew Thompson 	.getStringDesc = &eth_get_string_desc,
23302ac6454SAndrew Thompson 	.ppConfigDesc = eth_configs,
2341558eec6SEdward Tomasz Napierala 	.idVendor = ETH_DEFAULT_VENDOR_ID,
2351558eec6SEdward Tomasz Napierala 	.idProduct = ETH_DEFAULT_PRODUCT_ID,
23602ac6454SAndrew Thompson 	.bcdDevice = 0x0100,
23702ac6454SAndrew Thompson 	.bDeviceClass = UDCLASS_COMM,
23802ac6454SAndrew Thompson 	.bDeviceSubClass = 0,
23902ac6454SAndrew Thompson 	.bDeviceProtocol = 0,
2408e06491aSEdward Tomasz Napierala 	.iManufacturer = ETH_MANUFACTURER_INDEX,
2418e06491aSEdward Tomasz Napierala 	.iProduct = ETH_PRODUCT_INDEX,
2428e06491aSEdward Tomasz Napierala 	.iSerialNumber = ETH_SERIAL_NUMBER_INDEX,
24302ac6454SAndrew Thompson };
24402ac6454SAndrew Thompson 
24502ac6454SAndrew Thompson /*------------------------------------------------------------------------*
24602ac6454SAndrew Thompson  *	eth_get_string_desc
24702ac6454SAndrew Thompson  *
24802ac6454SAndrew Thompson  * Return values:
24902ac6454SAndrew Thompson  * NULL: Failure. No such string.
25002ac6454SAndrew Thompson  * Else: Success. Pointer to string descriptor is returned.
25102ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
25202ac6454SAndrew Thompson static const void *
eth_get_string_desc(uint16_t lang_id,uint8_t string_index)25302ac6454SAndrew Thompson eth_get_string_desc(uint16_t lang_id, uint8_t string_index)
25402ac6454SAndrew Thompson {
2558e06491aSEdward Tomasz Napierala 	static const void *ptr[ETH_MAX_INDEX] = {
2568e06491aSEdward Tomasz Napierala 		[ETH_LANG_INDEX] = &usb_string_lang_en,
2578e06491aSEdward Tomasz Napierala 		[ETH_MAC_INDEX] = &eth_mac,
2588e06491aSEdward Tomasz Napierala 		[ETH_CONTROL_INDEX] = &eth_control,
2598e06491aSEdward Tomasz Napierala 		[ETH_DATA_INDEX] = &eth_data,
2608e06491aSEdward Tomasz Napierala 		[ETH_CONFIGURATION_INDEX] = &eth_configuration,
2618e06491aSEdward Tomasz Napierala 		[ETH_MANUFACTURER_INDEX] = &eth_manufacturer,
2628e06491aSEdward Tomasz Napierala 		[ETH_PRODUCT_INDEX] = &eth_product,
2638e06491aSEdward Tomasz Napierala 		[ETH_SERIAL_NUMBER_INDEX] = &eth_serial_number,
26402ac6454SAndrew Thompson 	};
26502ac6454SAndrew Thompson 
26602ac6454SAndrew Thompson 	if (string_index == 0) {
26723ab0871SHans Petter Selasky 		return (&usb_string_lang_en);
26802ac6454SAndrew Thompson 	}
26902ac6454SAndrew Thompson 	if (lang_id != 0x0409) {
27002ac6454SAndrew Thompson 		return (NULL);
27102ac6454SAndrew Thompson 	}
2728e06491aSEdward Tomasz Napierala 	if (string_index < ETH_MAX_INDEX) {
27302ac6454SAndrew Thompson 		return (ptr[string_index]);
27402ac6454SAndrew Thompson 	}
27502ac6454SAndrew Thompson 	return (NULL);
27602ac6454SAndrew Thompson }
2778e06491aSEdward Tomasz Napierala 
2788e06491aSEdward Tomasz Napierala static void
eth_init(void * arg __unused)2798e06491aSEdward Tomasz Napierala eth_init(void *arg __unused)
2808e06491aSEdward Tomasz Napierala {
2818e06491aSEdward Tomasz Napierala 	struct sysctl_oid *parent;
2828e06491aSEdward Tomasz Napierala 	char parent_name[3];
2838e06491aSEdward Tomasz Napierala 
2848e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_mac, sizeof(eth_mac),
2858e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_MAC);
2868e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_control, sizeof(eth_control),
2878e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_CONTROL);
2888e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_data, sizeof(eth_data),
2898e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_DATA);
2908e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_configuration, sizeof(eth_configuration),
2918e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_CONFIG);
2928e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_manufacturer, sizeof(eth_manufacturer),
2938e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_MANUFACTURER);
2948e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_product, sizeof(eth_product),
2958e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_PRODUCT);
2968e06491aSEdward Tomasz Napierala 	usb_make_str_desc(&eth_serial_number, sizeof(eth_serial_number),
2978e06491aSEdward Tomasz Napierala 	    ETH_DEFAULT_SERIAL_NUMBER);
2988e06491aSEdward Tomasz Napierala 
2998e06491aSEdward Tomasz Napierala 	snprintf(parent_name, sizeof(parent_name), "%d", USB_TEMP_CDCE);
3008e06491aSEdward Tomasz Napierala 	sysctl_ctx_init(&eth_ctx_list);
3018e06491aSEdward Tomasz Napierala 
3028e06491aSEdward Tomasz Napierala 	parent = SYSCTL_ADD_NODE(&eth_ctx_list,
3038e06491aSEdward Tomasz Napierala 	    SYSCTL_STATIC_CHILDREN(_hw_usb_templates), OID_AUTO,
304f8d2b1f3SPawel Biernacki 	    parent_name, CTLFLAG_RW | CTLFLAG_MPSAFE,
3058e06491aSEdward Tomasz Napierala 	    0, "USB CDC Ethernet device side template");
3068e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_U16(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3078e06491aSEdward Tomasz Napierala 	    "vendor_id", CTLFLAG_RWTUN,
3088e06491aSEdward Tomasz Napierala 	    &usb_template_cdce.idVendor, 1, "Vendor identifier");
3098e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_U16(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3108e06491aSEdward Tomasz Napierala 	    "product_id", CTLFLAG_RWTUN,
3118e06491aSEdward Tomasz Napierala 	    &usb_template_cdce.idProduct, 1, "Product identifier");
3128e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3138e06491aSEdward Tomasz Napierala 	    "mac", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3148e06491aSEdward Tomasz Napierala 	    &eth_mac, sizeof(eth_mac), usb_temp_sysctl,
3158e06491aSEdward Tomasz Napierala 	    "A", "MAC address string");
3168e06491aSEdward Tomasz Napierala #if 0
3178e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3188e06491aSEdward Tomasz Napierala 	    "control", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3198e06491aSEdward Tomasz Napierala 	    &eth_control, sizeof(eth_control), usb_temp_sysctl,
3208e06491aSEdward Tomasz Napierala 	    "A", "Control interface string");
3218e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3228e06491aSEdward Tomasz Napierala 	    "data", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3238e06491aSEdward Tomasz Napierala 	    &eth_data, sizeof(eth_data), usb_temp_sysctl,
3248e06491aSEdward Tomasz Napierala 	    "A", "Data interface string");
3258e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3268e06491aSEdward Tomasz Napierala 	    "configuration", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3278e06491aSEdward Tomasz Napierala 	    &eth_configuration, sizeof(eth_configuration), usb_temp_sysctl,
3288e06491aSEdward Tomasz Napierala 	    "A", "Configuration string");
3298e06491aSEdward Tomasz Napierala #endif
3308e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3318e06491aSEdward Tomasz Napierala 	    "manufacturer", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3328e06491aSEdward Tomasz Napierala 	    &eth_manufacturer, sizeof(eth_manufacturer), usb_temp_sysctl,
3338e06491aSEdward Tomasz Napierala 	    "A", "Manufacturer string");
3348e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3358e06491aSEdward Tomasz Napierala 	    "product", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3368e06491aSEdward Tomasz Napierala 	    &eth_product, sizeof(eth_product), usb_temp_sysctl,
3378e06491aSEdward Tomasz Napierala 	    "A", "Product string");
3388e06491aSEdward Tomasz Napierala 	SYSCTL_ADD_PROC(&eth_ctx_list, SYSCTL_CHILDREN(parent), OID_AUTO,
3398e06491aSEdward Tomasz Napierala 	    "serial_number", CTLTYPE_STRING | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
3408e06491aSEdward Tomasz Napierala 	    &eth_serial_number, sizeof(eth_serial_number), usb_temp_sysctl,
3418e06491aSEdward Tomasz Napierala 	    "A", "Serial number string");
3428e06491aSEdward Tomasz Napierala }
3438e06491aSEdward Tomasz Napierala 
3448e06491aSEdward Tomasz Napierala static void
eth_uninit(void * arg __unused)3458e06491aSEdward Tomasz Napierala eth_uninit(void *arg __unused)
3468e06491aSEdward Tomasz Napierala {
3478e06491aSEdward Tomasz Napierala 
3488e06491aSEdward Tomasz Napierala 	sysctl_ctx_free(&eth_ctx_list);
3498e06491aSEdward Tomasz Napierala }
3508e06491aSEdward Tomasz Napierala 
3518e06491aSEdward Tomasz Napierala SYSINIT(eth_init, SI_SUB_LOCK, SI_ORDER_FIRST, eth_init, NULL);
352c70e38e4SHans Petter Selasky SYSUNINIT(eth_uninit, SI_SUB_LOCK, SI_ORDER_FIRST, eth_uninit, NULL);
353