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 2009 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef _USBSER_USBFTDI_UFTDI_VAR_H
27#define	_USBSER_USBFTDI_UFTDI_VAR_H
28
29/*
30 * USB UFTDI definitions
31 */
32
33#include <sys/types.h>
34#include <sys/dditypes.h>
35#include <sys/note.h>
36
37#include <sys/usb/clients/usbser/usbser_dsdi.h>
38
39#ifdef	__cplusplus
40extern "C" {
41#endif
42
43/*
44 * PM support
45 */
46typedef struct uftdi_pm {
47	uint8_t		pm_wakeup_enabled;	/* remote wakeup enabled */
48	uint8_t		pm_pwr_states;	/* bit mask of power states */
49	boolean_t	pm_raise_power;	/* driver is about to raise power */
50	uint8_t		pm_cur_power;	/* current power level */
51	uint_t		pm_busy_cnt;	/* number of set_busy requests */
52} uftdi_pm_t;
53
54typedef struct uftdi_regs {
55	uint16_t	ur_baud;
56	uint16_t	ur_data;
57	uint16_t	ur_flowval;
58	uint16_t	ur_flowidx;
59} uftdi_regs_t;
60
61_NOTE(SCHEME_PROTECTS_DATA("uftdi_regs", uftdi_regs))
62
63/*
64 * per device state structure
65 */
66typedef struct uftdi_state {
67	kmutex_t		uf_lock;		/* structure lock */
68	dev_info_t		*uf_dip;		/* device info */
69	int			uf_dev_flags;		/* device flags */
70	int			uf_port_state;		/* port state */
71	int			uf_port_flags;		/* port flags */
72	ds_cb_t			uf_cb;			/* DSD callbacks */
73
74	/*
75	 * USBA
76	 */
77	usb_client_dev_data_t	*uf_dev_data;		/* registration data */
78	usb_event_t		*uf_usb_events;		/* usb events */
79	usb_pipe_handle_t	uf_def_ph;		/* default pipe hdl */
80	usb_pipe_handle_t	uf_bulkin_ph;		/* in pipe hdl */
81	int			uf_bulkin_state;	/* in pipe state */
82	usb_pipe_handle_t	uf_bulkout_ph;		/* in pipe hdl */
83	int			uf_bulkout_state;	/* out pipe state */
84	usb_log_handle_t	uf_lh;			/* USBA log handle */
85	int			uf_dev_state;		/* USB device state */
86	size_t			uf_xfer_sz;		/* HCI bulk xfer size */
87
88	uftdi_pm_t		*uf_pm;			/* PM support */
89
90	/*
91	 * data receive and transmit
92	 */
93	mblk_t			*uf_rx_mp;		/* rx data */
94	mblk_t			*uf_tx_mp;		/* tx data */
95	kcondvar_t		uf_tx_cv;		/* tx completion */
96
97	/*
98	 * soft registers
99	 */
100	uftdi_regs_t		uf_softr;	/* config registers */
101	uint16_t		uf_mctl;	/* modem control */
102	uint8_t			uf_msr;		/* modem status */
103	uint8_t			uf_lsr;		/* line status register */
104
105} uftdi_state_t;
106
107_NOTE(MUTEX_PROTECTS_DATA(uftdi_state::uf_lock, uftdi_state))
108_NOTE(DATA_READABLE_WITHOUT_LOCK(uftdi_state::{
109	uf_dip
110	uf_dev_data
111	uf_usb_events
112	uf_def_ph
113	uf_lh
114	uf_xfer_sz
115	uf_pm
116	uf_port_state
117	uf_cb
118	uf_bulkin_ph
119	uf_bulkout_ph
120}))
121
122/* port state */
123enum {
124	UFTDI_PORT_CLOSED,			/* port is closed */
125	UFTDI_PORT_OPEN,			/* port is open */
126	UFTDI_PORT_CLOSING
127};
128
129/* port flags */
130enum {
131	UFTDI_PORT_TX_STOPPED	= 0x0001	/* transmit not allowed */
132};
133
134/* pipe state */
135enum {
136	UFTDI_PIPE_CLOSED,			/* pipe is closed */
137	UFTDI_PIPE_IDLE,			/* open but no requests */
138	UFTDI_PIPE_BUSY			/* servicing request */
139};
140
141/* various numbers */
142enum {
143	UFTDI_BULKOUT_TIMEOUT		= 15,	/* bulkout timeout */
144	UFTDI_BULKIN_TIMEOUT		= 15,	/* bulkin timeout */
145	UFTDI_XFER_SZ_MAX		= 64,	/* max xfer size */
146	UFTDI_CLEANUP_LEVEL_MAX	= 6	/* cleanup level */
147};
148
149
150/*
151 * debug printing masks
152 */
153#define	DPRINT_ATTACH		0x00000001
154#define	DPRINT_OPEN		0x00000002
155#define	DPRINT_CLOSE		0x00000004
156#define	DPRINT_DEF_PIPE		0x00000010
157#define	DPRINT_IN_PIPE		0x00000020
158#define	DPRINT_OUT_PIPE		0x00000040
159#define	DPRINT_IN_DATA		0x00000400
160#define	DPRINT_OUT_DATA		0x00000800
161#define	DPRINT_CTLOP		0x00001000
162#define	DPRINT_HOTPLUG		0x00002000
163#define	DPRINT_PM		0x00004000
164#define	DPRINT_MASK_ALL		0xFFFFFFFF
165
166#ifdef	__cplusplus
167}
168#endif
169
170#endif	/* _USBSER_USBFTDI_UFTDI_VAR_H */
171