xref: /onnv-gate/usr/src/uts/common/sys/usb/clients/usbser/usbsacm/usbsacm.h (revision 7492:2387323b838f)
13227Syq193411 /*
23227Syq193411  * CDDL HEADER START
33227Syq193411  *
43227Syq193411  * The contents of this file are subject to the terms of the
53227Syq193411  * Common Development and Distribution License (the "License").
63227Syq193411  * You may not use this file except in compliance with the License.
73227Syq193411  *
83227Syq193411  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93227Syq193411  * or http://www.opensolaris.org/os/licensing.
103227Syq193411  * See the License for the specific language governing permissions
113227Syq193411  * and limitations under the License.
123227Syq193411  *
133227Syq193411  * When distributing Covered Code, include this CDDL HEADER in each
143227Syq193411  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153227Syq193411  * If applicable, add the following below this CDDL HEADER, with the
163227Syq193411  * fields enclosed by brackets "[]" replaced with your own identifying
173227Syq193411  * information: Portions Copyright [yyyy] [name of copyright owner]
183227Syq193411  *
193227Syq193411  * CDDL HEADER END
203227Syq193411  */
213227Syq193411 /*
22*7492SZhigang.Lu@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233227Syq193411  * Use is subject to license terms.
243227Syq193411  */
253227Syq193411 
263227Syq193411 #ifndef _SYS_USB_USBSACM_H
273227Syq193411 #define	_SYS_USB_USBSACM_H
283227Syq193411 
293227Syq193411 
303227Syq193411 #include <sys/types.h>
313227Syq193411 #include <sys/dditypes.h>
323227Syq193411 #include <sys/note.h>
333227Syq193411 
343227Syq193411 #include <sys/usb/clients/usbser/usbser_dsdi.h>
353227Syq193411 
363227Syq193411 #ifdef	__cplusplus
373227Syq193411 extern "C" {
383227Syq193411 #endif
393227Syq193411 
403227Syq193411 
413227Syq193411 typedef struct usbsacm_port usbsacm_port_t;
423227Syq193411 typedef struct usbsacm_state usbsacm_state_t;
433227Syq193411 
443227Syq193411 
453227Syq193411 /*
463227Syq193411  * PM support
473227Syq193411  */
483227Syq193411 typedef struct usbsacm_power {
493227Syq193411 	uint8_t		pm_wakeup_enabled;	/* remote wakeup enabled */
503227Syq193411 	uint8_t		pm_pwr_states;	/* bit mask of power states */
513227Syq193411 	boolean_t	pm_raise_power;	/* driver is about to raise power */
523227Syq193411 	uint8_t		pm_cur_power;	/* current power level */
533227Syq193411 	uint_t		pm_busy_cnt;	/* number of set_busy requests */
543227Syq193411 } usbsacm_pm_t;
553227Syq193411 
563227Syq193411 
573227Syq193411 /*
583227Syq193411  * per bulk in/out structure
593227Syq193411  */
603227Syq193411 struct usbsacm_port {
613227Syq193411 	kmutex_t		acm_port_mutex;		/* structure lock */
623227Syq193411 	usbsacm_state_t		*acm_device;		/* back pointer */
633227Syq193411 	usb_pipe_handle_t	acm_bulkin_ph;		/* in pipe hdl */
643227Syq193411 	int			acm_bulkin_state;	/* in pipe state */
653227Syq193411 	usb_pipe_handle_t	acm_bulkout_ph;		/* out pipe hdl */
663227Syq193411 	int			acm_bulkout_state;	/* out pipe state */
673227Syq193411 	usb_pipe_handle_t	acm_intr_ph;		/* intr pipe hdl */
683227Syq193411 	int			acm_intr_state;		/* intr pipe state */
693227Syq193411 	usb_ep_descr_t		acm_intr_ep_descr;	/* ep descriptor */
703227Syq193411 	int			acm_ctrl_if_no;		/* control interface */
713227Syq193411 	int			acm_data_if_no;		/* data interface */
723227Syq193411 	int			acm_data_port_no;	/* which data port */
733227Syq193411 	ds_cb_t			acm_cb;			/* DSD callbacks */
743227Syq193411 	mblk_t			*acm_rx_mp;		/* rx data */
753227Syq193411 	mblk_t			*acm_tx_mp;		/* tx data */
763227Syq193411 	kcondvar_t		acm_tx_cv;		/* tx completion */
773227Syq193411 	uint8_t			acm_mctlout;		/* controls out */
783227Syq193411 	uint8_t			acm_mctlin;		/* controls in */
793227Syq193411 	int			acm_cap;		/* port capabilities */
803227Syq193411 	usb_cdc_line_coding_t	acm_line_coding;	/* port line coding */
813227Syq193411 	int			acm_port_state;		/* port state */
823227Syq193411 	size_t			acm_bulkin_size;	/* bulkin xfer size */
833227Syq193411 };
843227Syq193411 
853227Syq193411 _NOTE(MUTEX_PROTECTS_DATA(usbsacm_port::acm_port_mutex, usbsacm_port))
863227Syq193411 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbsacm_port::{
873227Syq193411 	acm_device
883227Syq193411 	acm_cb.cb_rx
893227Syq193411 	acm_cb.cb_tx
903227Syq193411 	acm_cb.cb_arg
913227Syq193411 	acm_bulkin_ph
923227Syq193411 	acm_bulkout_ph
933227Syq193411 	acm_intr_ph
943227Syq193411 	acm_ctrl_if_no
953227Syq193411 	acm_data_if_no
963227Syq193411 	acm_data_port_no
973227Syq193411 	acm_port_state
983227Syq193411 }))
993227Syq193411 
1003227Syq193411 struct usbsacm_state {
1013227Syq193411 	kmutex_t		acm_mutex;		/* structure lock */
1023227Syq193411 	dev_info_t		*acm_dip;		/* device info */
1033227Syq193411 	usb_client_dev_data_t	*acm_dev_data;		/* registration data */
1043227Syq193411 	usb_event_t		*acm_usb_events;	/* usb events */
1053227Syq193411 	usb_pipe_handle_t	acm_def_ph;		/* default pipe hdl */
1063227Syq193411 	usb_log_handle_t	acm_lh;			/* USBA log handle */
1073227Syq193411 	int			acm_dev_state;		/* USB device state */
1083227Syq193411 	size_t			acm_xfer_sz;		/* bulk xfer size */
1093227Syq193411 	boolean_t		acm_compatibility;	/* if conform to spec */
1103227Syq193411 	usbsacm_port_t		*acm_ports;		/* per port structs */
1113227Syq193411 	int			acm_port_cnt;		/* port number */
1123227Syq193411 	usbsacm_pm_t		*acm_pm;		/* PM support */
1133227Syq193411 };
1143227Syq193411 
1153227Syq193411 _NOTE(MUTEX_PROTECTS_DATA(usbsacm_state::acm_mutex, usbsacm_state))
1163227Syq193411 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbsacm_state::{
1173227Syq193411 	acm_dip
1183227Syq193411 	acm_dev_data
1193227Syq193411 	acm_usb_events
1203227Syq193411 	acm_def_ph
1213227Syq193411 	acm_lh
1223227Syq193411 	acm_dev_state
1233227Syq193411 	acm_xfer_sz
1243227Syq193411 	acm_compatibility
1253227Syq193411 	acm_ports
1263227Syq193411 	acm_port_cnt
1273227Syq193411 	acm_pm
1283227Syq193411 }))
1293227Syq193411 
1303227Syq193411 /* port state */
1313227Syq193411 enum {
1323227Syq193411 	USBSACM_PORT_CLOSED,			/* port is closed */
1333227Syq193411 	USBSACM_PORT_OPEN,			/* port is open */
1343227Syq193411 	USBSACM_PORT_CLOSING
1353227Syq193411 };
1363227Syq193411 
1373227Syq193411 /* pipe state */
1383227Syq193411 enum {
1393227Syq193411 	USBSACM_PIPE_CLOSED,			/* pipe is closed */
1403227Syq193411 	USBSACM_PIPE_IDLE,			/* open but no requests */
1413227Syq193411 	USBSACM_PIPE_BUSY,			/* servicing request */
1423227Syq193411 	USBSACM_PIPE_CLOSING			/* pipe is closing */
1433227Syq193411 };
1443227Syq193411 
1453227Syq193411 /* various tunables */
1463227Syq193411 enum {
1473227Syq193411 	USBSACM_BULKOUT_TIMEOUT		= 15,	/* bulkout timeout */
1483227Syq193411 	USBSACM_BULKIN_TIMEOUT		= 0	/* bulkin timeout */
1493227Syq193411 };
1503227Syq193411 
1513227Syq193411 /* hardware definitions */
1523227Syq193411 enum {
1533227Syq193411 	USBSACM_REQ_OUT	= USB_DEV_REQ_TYPE_CLASS| USB_DEV_REQ_HOST_TO_DEV,
1543227Syq193411 	USBSACM_REQ_IN	= USB_DEV_REQ_TYPE_CLASS | USB_DEV_REQ_DEV_TO_HOST,
1553227Syq193411 	USBSACM_REQ_WRITE_IF		= USBSACM_REQ_OUT | USB_DEV_REQ_RCPT_IF,
1563227Syq193411 	USBSACM_REQ_READ_IF		= USBSACM_REQ_IN | USB_DEV_REQ_RCPT_IF
1573227Syq193411 };
1583227Syq193411 
1593227Syq193411 #define	PRINT_MASK_ATTA		0x00000001
1603227Syq193411 #define	PRINT_MASK_CLOSE	0x00000002
1613227Syq193411 #define	PRINT_MASK_OPEN		0x00000004
1623227Syq193411 #define	PRINT_MASK_EVENTS	0x00000008
1633227Syq193411 #define	PRINT_MASK_PM		0x00000010
1643227Syq193411 #define	PRINT_MASK_CB		0x00000020
1653227Syq193411 #define	PRINT_MASK_ALL		0xFFFFFFFF
1663227Syq193411 
1673227Syq193411 
1683227Syq193411 #define	NELEM(a)	(sizeof (a) / sizeof (*(a)))
1693227Syq193411 
1703227Syq193411 
1713227Syq193411 #ifdef	__cplusplus
1723227Syq193411 }
1733227Syq193411 #endif
1743227Syq193411 
1753227Syq193411 #endif	/* _SYS_USB_USBSACM_H */
176