xref: /onnv-gate/usr/src/uts/common/sys/usb/clients/usbser/usbser_dsdi.h (revision 7492:2387323b838f)
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
52191Sszhou  * Common Development and Distribution License (the "License").
62191Sszhou  * 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*7492SZhigang.Lu@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 #ifndef _SYS_USB_USBSER_DSDI_H
270Sstevel@tonic-gate #define	_SYS_USB_USBSER_DSDI_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * USB-to-serial device-specific driver interface (DSDI)
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <sys/types.h>
350Sstevel@tonic-gate #include <sys/dditypes.h>
360Sstevel@tonic-gate #include <sys/usb/usba.h>
370Sstevel@tonic-gate #include <sys/usb/usba/usbai_private.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifdef	__cplusplus
400Sstevel@tonic-gate extern "C" {
410Sstevel@tonic-gate #endif
420Sstevel@tonic-gate 
430Sstevel@tonic-gate typedef void	*ds_hdl_t;	/* DSD device handler */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * interrupt emulation callbacks
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate typedef struct ds_cb {
490Sstevel@tonic-gate 	void		(*cb_tx)(caddr_t);	/* transmit callback */
500Sstevel@tonic-gate 	void		(*cb_rx)(caddr_t);	/* receive callback */
510Sstevel@tonic-gate 	void		(*cb_status)(caddr_t);	/* status change callback */
520Sstevel@tonic-gate 	caddr_t		cb_arg;			/* callback argument */
530Sstevel@tonic-gate } ds_cb_t;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate typedef struct ds_port_params ds_port_params_t;	/* see below */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate typedef struct ds_attach_info {
580Sstevel@tonic-gate 	/*
590Sstevel@tonic-gate 	 * passed to DSD:
600Sstevel@tonic-gate 	 */
610Sstevel@tonic-gate 	dev_info_t	*ai_dip;	/* devinfo */
620Sstevel@tonic-gate 	/*
630Sstevel@tonic-gate 	 * these event callbacks should be registered by DSD
640Sstevel@tonic-gate 	 * using usb_register_event_cbs()
650Sstevel@tonic-gate 	 */
660Sstevel@tonic-gate 	usb_event_t	*ai_usb_events;
670Sstevel@tonic-gate 	/*
680Sstevel@tonic-gate 	 * returned by DSD:
690Sstevel@tonic-gate 	 */
700Sstevel@tonic-gate 	ds_hdl_t	*ai_hdl; /* handle to be used by GSD in other calls */
710Sstevel@tonic-gate 	uint_t		*ai_port_cnt;	/* number of ports */
720Sstevel@tonic-gate } ds_attach_info_t;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate  * device operations used by Generic Serial Driver (GSD)
760Sstevel@tonic-gate  *
770Sstevel@tonic-gate  * ops returning int should return USB_SUCCESS on successful completion
780Sstevel@tonic-gate  * or appropriate USB_* error code in case of failure
790Sstevel@tonic-gate  *
800Sstevel@tonic-gate  * ops can block unless otherwise indicated
810Sstevel@tonic-gate  */
820Sstevel@tonic-gate typedef struct ds_ops {
830Sstevel@tonic-gate 	int	ds_version;	/* structure version */
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	/*
860Sstevel@tonic-gate 	 * configuration operations
870Sstevel@tonic-gate 	 * ------------------------
880Sstevel@tonic-gate 	 *
890Sstevel@tonic-gate 	 * attach/detach device instance, called from GSD attach(9E)/detach(9E)
900Sstevel@tonic-gate 	 */
910Sstevel@tonic-gate 	int	(*ds_attach)(ds_attach_info_t *aip);
920Sstevel@tonic-gate 	void	(*ds_detach)(ds_hdl_t);
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	/*
950Sstevel@tonic-gate 	 * register/unregister interrupt callbacks for the given port
960Sstevel@tonic-gate 	 */
970Sstevel@tonic-gate 	int	(*ds_register_cb)(ds_hdl_t, uint_t port_num, ds_cb_t *cb);
980Sstevel@tonic-gate 	void	(*ds_unregister_cb)(ds_hdl_t, uint_t port_num);
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	/*
1010Sstevel@tonic-gate 	 * open/close port
1020Sstevel@tonic-gate 	 */
1030Sstevel@tonic-gate 	int	(*ds_open_port)(ds_hdl_t, uint_t port_num);
1040Sstevel@tonic-gate 	int	(*ds_close_port)(ds_hdl_t, uint_t port_num);
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	/*
1070Sstevel@tonic-gate 	 * power management
1080Sstevel@tonic-gate 	 * ----------------
1090Sstevel@tonic-gate 	 *
1100Sstevel@tonic-gate 	 * set power level of the component;
1110Sstevel@tonic-gate 	 * DSD should set new_state to the resulting USB device state
1120Sstevel@tonic-gate 	 */
1130Sstevel@tonic-gate 	int	(*ds_usb_power)(ds_hdl_t, int comp, int level, int *new_state);
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	/*
1160Sstevel@tonic-gate 	 * CPR suspend/resume
1170Sstevel@tonic-gate 	 */
1180Sstevel@tonic-gate 	int	(*ds_suspend)(ds_hdl_t);
1190Sstevel@tonic-gate 	int	(*ds_resume)(ds_hdl_t);
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	/*
1220Sstevel@tonic-gate 	 * USB device disconnect/reconnect
1230Sstevel@tonic-gate 	 */
1240Sstevel@tonic-gate 	int	(*ds_disconnect)(ds_hdl_t);
1250Sstevel@tonic-gate 	int	(*ds_reconnect)(ds_hdl_t);
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	/*
1280Sstevel@tonic-gate 	 * standard UART operations
1290Sstevel@tonic-gate 	 * ------------------------
1300Sstevel@tonic-gate 	 *
1310Sstevel@tonic-gate 	 * set one or more port parameters: baud rate, parity,
1320Sstevel@tonic-gate 	 * stop bits, character size, xon/xoff char, flow control
1330Sstevel@tonic-gate 	 */
1340Sstevel@tonic-gate 	int	(*ds_set_port_params)(ds_hdl_t, uint_t port_num,
1350Sstevel@tonic-gate 			ds_port_params_t *tp);
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	/*
1380Sstevel@tonic-gate 	 * set modem controls: each bit set to 1 in 'mask' will be set to the
1390Sstevel@tonic-gate 	 * value of corresponding bit in 'val'; other bits are not affected
1400Sstevel@tonic-gate 	 */
1410Sstevel@tonic-gate 	int	(*ds_set_modem_ctl)(ds_hdl_t, uint_t port_num,
1420Sstevel@tonic-gate 			int mask, int val);
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	/*
1450Sstevel@tonic-gate 	 * get modem control/status: values of bits that correspond
1460Sstevel@tonic-gate 	 * to those set to 1 in 'mask' are returned in 'valp'
1470Sstevel@tonic-gate 	 */
1480Sstevel@tonic-gate 	int	(*ds_get_modem_ctl)(ds_hdl_t, uint_t port_num,
1490Sstevel@tonic-gate 			int mask, int *valp);
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 	/*
1520Sstevel@tonic-gate 	 * set/clear break ('ctl' is DS_ON/DS_OFF)
1530Sstevel@tonic-gate 	 */
1540Sstevel@tonic-gate 	int	(*ds_break_ctl)(ds_hdl_t, uint_t port_num, int ctl);
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	/*
1570Sstevel@tonic-gate 	 * set/clear internal loopback ('ctl' is DS_ON/DS_OFF)
1580Sstevel@tonic-gate 	 */
1590Sstevel@tonic-gate 	int	(*ds_loopback)(ds_hdl_t, uint_t port_num, int ctl);
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	/*
1620Sstevel@tonic-gate 	 * data xfer
1630Sstevel@tonic-gate 	 * ---------
1640Sstevel@tonic-gate 	 *
1650Sstevel@tonic-gate 	 * data transmit: DSD is *required* to accept mblk for transfer and
1660Sstevel@tonic-gate 	 * return USB_SUCCESS; after which GSD no longer owns the mblk
1670Sstevel@tonic-gate 	 */
1680Sstevel@tonic-gate 	int	(*ds_tx)(ds_hdl_t, uint_t port_num, mblk_t *mp);
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	/*
1710Sstevel@tonic-gate 	 * data receipt: DSD returns either received data mblk or NULL
1720Sstevel@tonic-gate 	 * if no data available. this op must not block as it is intended
1730Sstevel@tonic-gate 	 * to be called from is usually called GSD receive callback
1740Sstevel@tonic-gate 	 */
1750Sstevel@tonic-gate 	mblk_t	*(*ds_rx)(ds_hdl_t, uint_t port_num);
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	/*
1780Sstevel@tonic-gate 	 * stop/start data transmit or/and receive:
1790Sstevel@tonic-gate 	 * 'dir' can be an OR of DS_TX and DS_RX; must succeed.
1800Sstevel@tonic-gate 	 */
1810Sstevel@tonic-gate 	void	(*ds_stop)(ds_hdl_t, uint_t port_num, int dir);
1820Sstevel@tonic-gate 	void	(*ds_start)(ds_hdl_t, uint_t port_num, int dir);
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 	/*
1850Sstevel@tonic-gate 	 * flush FIFOs: 'dir' can be an OR of DS_TX and DS_RX,
1860Sstevel@tonic-gate 	 * affecting transmit and received FIFO respectively
1870Sstevel@tonic-gate 	 */
1880Sstevel@tonic-gate 	int	(*ds_fifo_flush)(ds_hdl_t, uint_t port_num, int dir);
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 	/*
1910Sstevel@tonic-gate 	 * drain (wait until empty) output FIFO
1920Sstevel@tonic-gate 	 *
1930Sstevel@tonic-gate 	 * return failure if the FIFO does not get empty after at least
1940Sstevel@tonic-gate 	 * 'timeout' seconds (zero timeout means wait forever)
1950Sstevel@tonic-gate 	 */
1960Sstevel@tonic-gate 	int	(*ds_fifo_drain)(ds_hdl_t, uint_t port_num, int timeout);
1972191Sszhou 
1982191Sszhou 	/* V1 ops for polled I/O */
1992191Sszhou 	usb_pipe_handle_t (*ds_out_pipe)(ds_hdl_t, uint_t port_num);
2002191Sszhou 	usb_pipe_handle_t (*ds_in_pipe)(ds_hdl_t, uint_t port_num);
2010Sstevel@tonic-gate } ds_ops_t;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate /*
2040Sstevel@tonic-gate  * ds_version
2050Sstevel@tonic-gate  */
2060Sstevel@tonic-gate enum {
2070Sstevel@tonic-gate 	DS_OPS_VERSION_V0	= 0,
2082191Sszhou 	DS_OPS_VERSION_V1	= 1,
2092191Sszhou 	DS_OPS_VERSION		= DS_OPS_VERSION_V1
2100Sstevel@tonic-gate };
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate /*
2130Sstevel@tonic-gate  * parameter type
2140Sstevel@tonic-gate  */
2150Sstevel@tonic-gate typedef enum {
2160Sstevel@tonic-gate 	DS_PARAM_BAUD,		/* baud rate */
2170Sstevel@tonic-gate 	DS_PARAM_PARITY,	/* parity */
2180Sstevel@tonic-gate 	DS_PARAM_STOPB,		/* stop bits */
2190Sstevel@tonic-gate 	DS_PARAM_CHARSZ,	/* char size */
2200Sstevel@tonic-gate 	DS_PARAM_XON_XOFF,	/* xon/xoff chars */
2210Sstevel@tonic-gate 	DS_PARAM_FLOW_CTL	/* flow control */
2220Sstevel@tonic-gate } ds_port_param_type_t;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate /*
2250Sstevel@tonic-gate  * a single param entry, union used to pass various data types
2260Sstevel@tonic-gate  */
2270Sstevel@tonic-gate typedef struct ds_port_param_entry {
2280Sstevel@tonic-gate 	ds_port_param_type_t	param;	 /* parameter */
2290Sstevel@tonic-gate 	union {
2300Sstevel@tonic-gate 		uint_t		ui;
2310Sstevel@tonic-gate 		uchar_t		uc[4];
2320Sstevel@tonic-gate 	} val;			/* parameter value(s) */
2330Sstevel@tonic-gate } ds_port_param_entry_t;
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate /*
2360Sstevel@tonic-gate  * port parameter array
2370Sstevel@tonic-gate  */
2380Sstevel@tonic-gate struct ds_port_params {
2390Sstevel@tonic-gate 	ds_port_param_entry_t	*tp_entries;	/* entry array */
2400Sstevel@tonic-gate 	int			tp_cnt;		/* entry count */
2410Sstevel@tonic-gate };
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate /*
2440Sstevel@tonic-gate  * direction (ds_fifo_flush, ds_fifo_drain)
2450Sstevel@tonic-gate  */
2460Sstevel@tonic-gate enum {
2470Sstevel@tonic-gate 	DS_TX		= 0x01,	/* transmit direction */
2480Sstevel@tonic-gate 	DS_RX		= 0x02	/* receive direction */
2490Sstevel@tonic-gate };
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate /*
2520Sstevel@tonic-gate  * on/off (ds_break_ctl, ds_loopback)
2530Sstevel@tonic-gate  */
2540Sstevel@tonic-gate enum {
2550Sstevel@tonic-gate 	DS_OFF,
2560Sstevel@tonic-gate 	DS_ON
2570Sstevel@tonic-gate };
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate /*
2600Sstevel@tonic-gate  * input error codes, returned by DSD in an M_BREAK message
2610Sstevel@tonic-gate  */
2620Sstevel@tonic-gate enum {
2630Sstevel@tonic-gate 	DS_PARITY_ERR	= 0x01,	/* parity error */
2640Sstevel@tonic-gate 	DS_FRAMING_ERR	= 0x02,	/* framing error */
2650Sstevel@tonic-gate 	DS_OVERRUN_ERR	= 0x03,	/* data overrun */
2660Sstevel@tonic-gate 	DS_BREAK_ERR	= 0x04	/* break detected */
2670Sstevel@tonic-gate };
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate #ifdef	__cplusplus
2700Sstevel@tonic-gate }
2710Sstevel@tonic-gate #endif
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate #endif	/* _SYS_USB_USBSER_DSDI_H */
274