xref: /illumos-gate/usr/src/uts/common/sys/usb/clients/printer/usbprn.h (revision 4de2612967d06c4fdbf524a62556a1e8118a006f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  *
22  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_USB_USBPRN_H
27 #define	_SYS_USB_USBPRN_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/usb/usba/usbai_private.h>
36 
37 /*
38  * This header file contains internal driver structures info
39  *
40  * Write timeout values for 1K of data transfer
41  */
42 #define	USBPRN_XFER_TIMEOUT	90	/* default timeout is 90 seconds */
43 #define	USBPRN_XFER_TIMEOUT_MIN	1	/* min timeout is 1 second */
44 #define	USBPRN_XFER_TIMEOUT_MAX	300	/* max timeout is 5 minutes */
45 
46 /* ps_flags values */
47 #define	USBPRN_PS_IDLE			0x00 /* no activity on any pipe */
48 #define	USBPRN_PS_NEED_TO_XFER		0x01 /* transfer to start */
49 
50 /* Maximum transfer size */
51 #define	USBPRN_MAX_XFER_SIZE	(8 * 1024)
52 
53 /*
54  * Per pipe state information
55  */
56 typedef struct usbprn_ps {
57 	usb_ep_descr_t		ps_ept_descr;	/* endpoint descriptor */
58 	usb_pipe_handle_t	ps_handle;	/* pipe handle */
59 	usb_pipe_policy_t	ps_policy;	/* pipe policy */
60 	int			ps_flags;	/* state flags */
61 	int			ps_cr;		/* save last cr */
62 } usbprn_ps_t;
63 
64 _NOTE(SCHEME_PROTECTS_DATA("USBA", usbprn_ps::ps_handle))
65 
66 /*
67  * PM support
68  */
69 typedef struct usbprn_power  {
70 	/* device busy accounting */
71 	int		usbprn_pm_busy;
72 	uint8_t		usbprn_wakeup_enabled;
73 
74 	/* this is the bit mask of the power states that device has */
75 	uint8_t		usbprn_pwr_states;
76 
77 	/* wakeup and power transistion capabilites of an interface */
78 	uint8_t		usbprn_pm_capabilities;
79 
80 	uint8_t		usbprn_current_power;
81 } usbprn_power_t;
82 
83 
84 /*
85  * State structure
86  */
87 typedef struct usbprn_state {
88 	dev_info_t	*usbprn_dip;		/* per-device info handle */
89 	int		usbprn_dev_state;	/* USB device state */
90 	kmutex_t	usbprn_mutex;		/* for general locking */
91 	int		usbprn_instance;	/* instance number */
92 	int		usbprn_flags;
93 
94 	usb_client_dev_data_t *usbprn_dev_data;	/* registration data */
95 
96 	size_t		usbprn_max_bulk_xfer_size;	/* max txfer size */
97 	char		*usbprn_device_id;	/* Device id string */
98 	int		usbprn_device_id_len;	/* Device id length */
99 
100 	/* serialize access */
101 	usb_serialization_t usbprn_ser_acc;
102 	usb_serialization_t usbprn_write_acc;
103 	usb_serialization_t usbprn_dev_acc;
104 
105 	/* mblk_t that contains the data to be sent */
106 	mblk_t		*usbprn_bulk_mp;
107 
108 	struct	buf	*usbprn_bp;		/* Buffer ptr for strategy */
109 
110 	usb_pipe_handle_t usbprn_def_ph;	/* default pipe handle */
111 
112 	usbprn_ps_t	usbprn_bulk_out;	/* bulk out info */
113 	usbprn_ps_t	usbprn_bulk_in;		/* bulk in info */
114 
115 	usb_log_handle_t usbprn_log_handle;	/* log handle */
116 	usb_cfg_descr_t usbprn_config_descr;	/* config desc */
117 	usb_if_descr_t	 usbprn_if_descr;	/* interface descr */
118 
119 	char		usbprn_last_status;	/* last port status */
120 
121 	usbprn_power_t	*usbprn_pm;		/* Power components */
122 
123 	struct ecpp_transfer_parms usbprn_setparms; /* Set xfer parameters */
124 	struct prn_timeouts	usbprn_prn_timeouts;	/* prnio timeouts */
125 
126 	usb_ugen_hdl_t	usbprn_ugen_hdl;		/* ugen support */
127 } usbprn_state_t;
128 
129 /* warlock directives, stable data */
130 _NOTE(MUTEX_PROTECTS_DATA(usbprn_state_t::usbprn_mutex, usbprn_state_t))
131 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_dip))
132 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_ugen_hdl))
133 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_pm))
134 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_instance))
135 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_log_handle))
136 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_if_descr))
137 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_dev_data))
138 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_ser_acc))
139 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_write_acc))
140 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_dev_acc))
141 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_def_ph))
142 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_device_id))
143 _NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_device_id_len))
144 _NOTE(SCHEME_PROTECTS_DATA("stable data", usb_pipe_policy))
145 _NOTE(SCHEME_PROTECTS_DATA("unshared data", mblk_t))
146 _NOTE(SCHEME_PROTECTS_DATA("unshared data", usb_bulk_req))
147 
148 
149 /* Values for usbprn_flags */
150 #define	USBPRN_LOCKS_INIT_DONE	0x01	/* locks have been init'ed */
151 #define	USBPRN_OPEN		0x02	/* Device is open */
152 
153 
154 /* Macros */
155 
156 /*
157  * Check if it the device is not being closed
158  * or not being disconnected or not being suspended
159  */
160 #define	USBPRN_DEVICE_ACCESS_OK(s) \
161 	(((s)->usbprn_flags & USBPRN_OPEN) && \
162 	(((s)->usbprn_dev_state == USB_DEV_ONLINE)))
163 
164 /* Check if the pipes are idle or closed */
165 #define	USBPRN_PIPES_BUSY(s) \
166 	(((s)->usbprn_default.ps_flags != USBPRN_PS_IDLE) || \
167 	((s)->usbprn_bulk_out.ps_flags != USBPRN_PS_IDLE) || \
168 	((s)->usbprn_bulk_in.ps_flags != USBPRN_PS_IDLE))
169 
170 /*
171  * Debug message Masks
172  */
173 #define	PRINT_MASK_ATTA		0x00000001	/* attach/detach */
174 #define	PRINT_MASK_OPEN		0x00000002
175 #define	PRINT_MASK_CLOSE	0x00000004
176 #define	PRINT_MASK_EVENTS	0x00000008
177 #define	PRINT_MASK_PM		0x00000010
178 #define	PRINT_MASK_CPR		0x00000020
179 #define	PRINT_MASK_ALL		0xFFFFFFFF
180 
181 /* log message breakup */
182 #define	USBPRN_PRINT_MAXLINE	80
183 
184 /* max device id length */
185 #define	USBPRN_MAX_DEVICE_ID_LENGTH	1024
186 
187 /* ugen support */
188 #define	USBPRN_MINOR_UGEN_BITS_MASK	0xff
189 #define	USBPRN_MINOR_INSTANCE_SHIFT	8
190 #define	USBPRN_MINOR_INSTANCE_MASK	~USBPRN_MINOR_UGEN_BITS_MASK
191 #define	USBPRN_MINOR_TO_INSTANCE(minor) \
192 	(((minor) & USBPRN_MINOR_INSTANCE_MASK) >> \
193 	USBPRN_MINOR_INSTANCE_SHIFT)
194 
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #endif	/* _SYS_USB_USBPRN_H */
201