pl2303_var.h revision 7492:2387323b838f
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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef _SYS_USB_USBSER_PL2303_VAR_H
27#define	_SYS_USB_USBSER_PL2303_VAR_H
28
29
30/*
31 * USB PL2303 definitions
32 */
33
34#include <sys/types.h>
35#include <sys/dditypes.h>
36#include <sys/note.h>
37
38#include <sys/usb/clients/usbser/usbser_dsdi.h>
39
40#ifdef	__cplusplus
41extern "C" {
42#endif
43
44/*
45 * PM support
46 */
47typedef struct pl2303_power {
48	uint8_t		pm_wakeup_enabled;	/* remote wakeup enabled */
49	uint8_t		pm_pwr_states;	/* bit mask of power states */
50	boolean_t	pm_raise_power;	/* driver is about to raise power */
51	uint8_t		pm_cur_power;	/* current power level */
52	uint_t		pm_busy_cnt;	/* number of set_busy requests */
53} pl2303_pm_t;
54
55
56/*
57 * From device driver's perspective, there is no difference
58 * between PL-2303HX(Chip A) and PL-2303X chips, so PL-2303X will
59 * stand for two chiptypes
60 */
61enum pl2303_chip {
62	pl2303_H,		/* PL-2303H chip */
63	pl2303_X,		/* PL-2303X chip or PL-2303HX(Chip A) */
64	pl2303_HX_CHIP_D,	/* PL-2303HX(Chip D) */
65	pl2303_UNKNOWN		/* Unknown chip type */
66};
67
68/*
69 * per device state structure
70 */
71typedef struct pl2303_state {
72	kmutex_t		pl_mutex;		/* structure lock */
73	dev_info_t		*pl_dip;		/* device info */
74	int			pl_dev_flags;		/* device flags */
75	int			pl_port_state;		/* port state */
76	int			pl_port_flags;		/* port flags */
77	ds_cb_t			pl_cb;			/* DSD callbacks */
78	/*
79	 * USBA
80	 */
81	usb_client_dev_data_t	*pl_dev_data;		/* registration data */
82	usb_event_t		*pl_usb_events;		/* usb events */
83	usb_pipe_handle_t	pl_def_ph;		/* default pipe hdl */
84	usb_pipe_handle_t	pl_bulkin_ph;		/* in pipe hdl */
85	int			pl_bulkin_state;	/* in pipe state */
86	usb_pipe_handle_t	pl_bulkout_ph;		/* in pipe hdl */
87	int			pl_bulkout_state;	/* out pipe state */
88	usb_log_handle_t	pl_lh;			/* USBA log handle */
89	int			pl_dev_state;		/* USB device state */
90	size_t			pl_xfer_sz;		/* HCI bulk xfer size */
91	pl2303_pm_t		*pl_pm;			/* PM support */
92	/*
93	 * data receipt and transmit
94	 */
95	mblk_t			*pl_rx_mp;		/* rx data */
96	mblk_t			*pl_tx_mp;		/* tx data */
97	kcondvar_t		pl_tx_cv;		/* tx completion */
98	/*
99	 * other
100	 */
101	uint8_t			pl_mctl;		/* modem controls */
102	enum pl2303_chip	pl_chiptype;		/* chip type */
103} pl2303_state_t;
104
105_NOTE(MUTEX_PROTECTS_DATA(pl2303_state::pl_mutex, pl2303_state))
106_NOTE(DATA_READABLE_WITHOUT_LOCK(pl2303_state::{
107	pl_dip
108	pl_dev_data
109	pl_usb_events
110	pl_def_ph
111	pl_lh
112	pl_xfer_sz
113	pl_pm
114	pl_port_state
115	pl_cb.cb_rx
116	pl_cb.cb_tx
117	pl_cb.cb_arg
118	pl_bulkin_ph
119	pl_bulkout_ph
120	pl_chiptype
121}))
122
123
124/* port state */
125enum {
126	PL2303_PORT_CLOSED,			/* port is closed */
127	PL2303_PORT_OPEN,			/* port is open */
128	PL2303_PORT_CLOSING
129};
130
131/* port flags */
132enum {
133	PL2303_PORT_TX_STOPPED	= 0x0001	/* transmit not allowed */
134};
135
136/* pipe state */
137enum {
138	PL2303_PIPE_CLOSED,			/* pipe is closed */
139	PL2303_PIPE_IDLE,			/* open but no requests */
140	PL2303_PIPE_BUSY			/* servicing request */
141};
142
143/* various tunables */
144enum {
145	PL2303_BULKOUT_TIMEOUT		= 15,	/* bulkout timeout */
146	PL2303_BULKIN_TIMEOUT		= 15,	/* bulkin timeout */
147	PL2303_XFER_SZ_MAX		= 64,	/* max xfer size */
148	PL2303_CLEANUP_LEVEL_MAX	= 6	/* cleanup level */
149};
150
151
152/*
153 * debug printing masks
154 */
155#define	DPRINT_ATTACH		0x00000001
156#define	DPRINT_OPEN		0x00000002
157#define	DPRINT_CLOSE		0x00000004
158#define	DPRINT_DEF_PIPE		0x00000010
159#define	DPRINT_IN_PIPE		0x00000020
160#define	DPRINT_OUT_PIPE		0x00000040
161#define	DPRINT_IN_DATA		0x00000400
162#define	DPRINT_OUT_DATA		0x00000800
163#define	DPRINT_CTLOP		0x00001000
164#define	DPRINT_HOTPLUG		0x00002000
165#define	DPRINT_PM		0x00004000
166#define	DPRINT_MASK_ALL		0xFFFFFFFF
167
168
169/*
170 * misc macros
171 */
172#define	NELEM(a)	(sizeof (a) / sizeof (*(a)))
173
174#ifdef	__cplusplus
175}
176#endif
177
178#endif	/* _SYS_USB_USBSER_PL2303_VAR_H */
179