xref: /onnv-gate/usr/src/uts/common/sys/usb/clients/printer/usbprn.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
5*7492SZhigang.Lu@Sun.COM  * Common Development and Distribution License (the "License").
6*7492SZhigang.Lu@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  *
21*7492SZhigang.Lu@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
220Sstevel@tonic-gate  * Use is subject to license terms.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef _SYS_USB_USBPRN_H
260Sstevel@tonic-gate #define	_SYS_USB_USBPRN_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef	__cplusplus
300Sstevel@tonic-gate extern "C" {
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <sys/usb/usba/usbai_private.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * This header file contains internal driver structures info
370Sstevel@tonic-gate  *
380Sstevel@tonic-gate  * Write timeout values for 1K of data transfer
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate #define	USBPRN_XFER_TIMEOUT	90	/* default timeout is 90 seconds */
410Sstevel@tonic-gate #define	USBPRN_XFER_TIMEOUT_MIN	1	/* min timeout is 1 second */
420Sstevel@tonic-gate #define	USBPRN_XFER_TIMEOUT_MAX	300	/* max timeout is 5 minutes */
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /* ps_flags values */
450Sstevel@tonic-gate #define	USBPRN_PS_IDLE			0x00 /* no activity on any pipe */
460Sstevel@tonic-gate #define	USBPRN_PS_NEED_TO_XFER		0x01 /* transfer to start */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /* Maximum transfer size */
490Sstevel@tonic-gate #define	USBPRN_MAX_XFER_SIZE	(8 * 1024)
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * Per pipe state information
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate typedef struct usbprn_ps {
550Sstevel@tonic-gate 	usb_ep_descr_t		ps_ept_descr;	/* endpoint descriptor */
560Sstevel@tonic-gate 	usb_pipe_handle_t	ps_handle;	/* pipe handle */
570Sstevel@tonic-gate 	usb_pipe_policy_t	ps_policy;	/* pipe policy */
580Sstevel@tonic-gate 	int			ps_flags;	/* state flags */
590Sstevel@tonic-gate 	int			ps_cr;		/* save last cr */
600Sstevel@tonic-gate } usbprn_ps_t;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("USBA", usbprn_ps::ps_handle))
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate  * PM support
660Sstevel@tonic-gate  */
670Sstevel@tonic-gate typedef struct usbprn_power  {
680Sstevel@tonic-gate 	/* device busy accounting */
690Sstevel@tonic-gate 	int		usbprn_pm_busy;
700Sstevel@tonic-gate 	uint8_t		usbprn_wakeup_enabled;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	/* this is the bit mask of the power states that device has */
730Sstevel@tonic-gate 	uint8_t		usbprn_pwr_states;
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	/* wakeup and power transistion capabilites of an interface */
760Sstevel@tonic-gate 	uint8_t		usbprn_pm_capabilities;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	uint8_t		usbprn_current_power;
790Sstevel@tonic-gate } usbprn_power_t;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate  * State structure
840Sstevel@tonic-gate  */
850Sstevel@tonic-gate typedef struct usbprn_state {
860Sstevel@tonic-gate 	dev_info_t	*usbprn_dip;		/* per-device info handle */
870Sstevel@tonic-gate 	int		usbprn_dev_state;	/* USB device state */
880Sstevel@tonic-gate 	kmutex_t	usbprn_mutex;		/* for general locking */
890Sstevel@tonic-gate 	int		usbprn_instance;	/* instance number */
900Sstevel@tonic-gate 	int		usbprn_flags;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	usb_client_dev_data_t *usbprn_dev_data;	/* registration data */
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	size_t		usbprn_max_bulk_xfer_size;	/* max txfer size */
950Sstevel@tonic-gate 	char		*usbprn_device_id;	/* Device id string */
960Sstevel@tonic-gate 	int		usbprn_device_id_len;	/* Device id length */
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	/* serialize access */
990Sstevel@tonic-gate 	usb_serialization_t usbprn_ser_acc;
1000Sstevel@tonic-gate 	usb_serialization_t usbprn_write_acc;
1010Sstevel@tonic-gate 	usb_serialization_t usbprn_dev_acc;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	/* mblk_t that contains the data to be sent */
1040Sstevel@tonic-gate 	mblk_t		*usbprn_bulk_mp;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	struct	buf	*usbprn_bp;		/* Buffer ptr for strategy */
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	usb_pipe_handle_t usbprn_def_ph;	/* default pipe handle */
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	usbprn_ps_t	usbprn_bulk_out;	/* bulk out info */
1110Sstevel@tonic-gate 	usbprn_ps_t	usbprn_bulk_in;		/* bulk in info */
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	usb_log_handle_t usbprn_log_handle;	/* log handle */
1140Sstevel@tonic-gate 	usb_cfg_descr_t usbprn_config_descr;	/* config desc */
1150Sstevel@tonic-gate 	usb_if_descr_t	 usbprn_if_descr;	/* interface descr */
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	char		usbprn_last_status;	/* last port status */
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	usbprn_power_t	*usbprn_pm;		/* Power components */
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	struct ecpp_transfer_parms usbprn_setparms; /* Set xfer parameters */
1220Sstevel@tonic-gate 	struct prn_timeouts	usbprn_prn_timeouts;	/* prnio timeouts */
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	usb_ugen_hdl_t	usbprn_ugen_hdl;		/* ugen support */
1250Sstevel@tonic-gate } usbprn_state_t;
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate /* warlock directives, stable data */
1280Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(usbprn_state_t::usbprn_mutex, usbprn_state_t))
1290Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_dip))
1300Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_ugen_hdl))
1310Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_pm))
1320Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_instance))
1330Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_log_handle))
1340Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_if_descr))
1350Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_dev_data))
1360Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_ser_acc))
1370Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_write_acc))
1380Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_dev_acc))
1390Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_def_ph))
1400Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_device_id))
1410Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_device_id_len))
1420Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", usb_pipe_policy))
1430Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", mblk_t))
1440Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", usb_bulk_req))
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate /* Values for usbprn_flags */
1480Sstevel@tonic-gate #define	USBPRN_LOCKS_INIT_DONE	0x01	/* locks have been init'ed */
1490Sstevel@tonic-gate #define	USBPRN_OPEN		0x02	/* Device is open */
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate /* Macros */
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate /*
1550Sstevel@tonic-gate  * Check if it the device is not being closed
1560Sstevel@tonic-gate  * or not being disconnected or not being suspended
1570Sstevel@tonic-gate  */
1580Sstevel@tonic-gate #define	USBPRN_DEVICE_ACCESS_OK(s) \
1590Sstevel@tonic-gate 	(((s)->usbprn_flags & USBPRN_OPEN) && \
1600Sstevel@tonic-gate 	(((s)->usbprn_dev_state == USB_DEV_ONLINE)))
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate /* Check if the pipes are idle or closed */
1630Sstevel@tonic-gate #define	USBPRN_PIPES_BUSY(s) \
1640Sstevel@tonic-gate 	(((s)->usbprn_default.ps_flags != USBPRN_PS_IDLE) || \
1650Sstevel@tonic-gate 	((s)->usbprn_bulk_out.ps_flags != USBPRN_PS_IDLE) || \
1660Sstevel@tonic-gate 	((s)->usbprn_bulk_in.ps_flags != USBPRN_PS_IDLE))
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate /*
1690Sstevel@tonic-gate  * Debug message Masks
1700Sstevel@tonic-gate  */
1710Sstevel@tonic-gate #define	PRINT_MASK_ATTA		0x00000001	/* attach/detach */
1720Sstevel@tonic-gate #define	PRINT_MASK_OPEN		0x00000002
1730Sstevel@tonic-gate #define	PRINT_MASK_CLOSE	0x00000004
1740Sstevel@tonic-gate #define	PRINT_MASK_EVENTS	0x00000008
1750Sstevel@tonic-gate #define	PRINT_MASK_PM		0x00000010
1760Sstevel@tonic-gate #define	PRINT_MASK_CPR		0x00000020
1770Sstevel@tonic-gate #define	PRINT_MASK_ALL		0xFFFFFFFF
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate /* log message breakup */
1800Sstevel@tonic-gate #define	USBPRN_PRINT_MAXLINE	80
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate /* max device id length */
1830Sstevel@tonic-gate #define	USBPRN_MAX_DEVICE_ID_LENGTH	1024
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate /* ugen support */
1860Sstevel@tonic-gate #define	USBPRN_MINOR_UGEN_BITS_MASK	0xff
1870Sstevel@tonic-gate #define	USBPRN_MINOR_INSTANCE_SHIFT	8
1880Sstevel@tonic-gate #define	USBPRN_MINOR_INSTANCE_MASK	~USBPRN_MINOR_UGEN_BITS_MASK
1890Sstevel@tonic-gate #define	USBPRN_MINOR_TO_INSTANCE(minor) \
1900Sstevel@tonic-gate 	(((minor) & USBPRN_MINOR_INSTANCE_MASK) >> \
1910Sstevel@tonic-gate 	USBPRN_MINOR_INSTANCE_SHIFT)
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate #ifdef __cplusplus
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate #endif
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate #endif	/* _SYS_USB_USBPRN_H */
199