17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
5d29f5a7zhigang lu - Sun Microsystems - Beijing China * Common Development and Distribution License (the "License").
6d29f5a7zhigang lu - Sun Microsystems - Beijing China * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate *
21d29f5a7zhigang lu - Sun Microsystems - Beijing China * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
227c478bdstevel@tonic-gate * Use is subject to license terms.
237c478bdstevel@tonic-gate */
247c478bdstevel@tonic-gate
257c478bdstevel@tonic-gate#ifndef _SYS_USB_USBPRN_H
267c478bdstevel@tonic-gate#define	_SYS_USB_USBPRN_H
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate#ifdef	__cplusplus
307c478bdstevel@tonic-gateextern "C" {
317c478bdstevel@tonic-gate#endif
327c478bdstevel@tonic-gate
337c478bdstevel@tonic-gate#include <sys/usb/usba/usbai_private.h>
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate/*
367c478bdstevel@tonic-gate * This header file contains internal driver structures info
377c478bdstevel@tonic-gate *
387c478bdstevel@tonic-gate * Write timeout values for 1K of data transfer
397c478bdstevel@tonic-gate */
407c478bdstevel@tonic-gate#define	USBPRN_XFER_TIMEOUT	90	/* default timeout is 90 seconds */
417c478bdstevel@tonic-gate#define	USBPRN_XFER_TIMEOUT_MIN	1	/* min timeout is 1 second */
427c478bdstevel@tonic-gate#define	USBPRN_XFER_TIMEOUT_MAX	300	/* max timeout is 5 minutes */
437c478bdstevel@tonic-gate
447c478bdstevel@tonic-gate/* ps_flags values */
457c478bdstevel@tonic-gate#define	USBPRN_PS_IDLE			0x00 /* no activity on any pipe */
467c478bdstevel@tonic-gate#define	USBPRN_PS_NEED_TO_XFER		0x01 /* transfer to start */
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gate/* Maximum transfer size */
497c478bdstevel@tonic-gate#define	USBPRN_MAX_XFER_SIZE	(8 * 1024)
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gate/*
527c478bdstevel@tonic-gate * Per pipe state information
537c478bdstevel@tonic-gate */
547c478bdstevel@tonic-gatetypedef struct usbprn_ps {
557c478bdstevel@tonic-gate	usb_ep_descr_t		ps_ept_descr;	/* endpoint descriptor */
567c478bdstevel@tonic-gate	usb_pipe_handle_t	ps_handle;	/* pipe handle */
577c478bdstevel@tonic-gate	usb_pipe_policy_t	ps_policy;	/* pipe policy */
587c478bdstevel@tonic-gate	int			ps_flags;	/* state flags */
597c478bdstevel@tonic-gate	int			ps_cr;		/* save last cr */
607c478bdstevel@tonic-gate} usbprn_ps_t;
617c478bdstevel@tonic-gate
627c478bdstevel@tonic-gate_NOTE(SCHEME_PROTECTS_DATA("USBA", usbprn_ps::ps_handle))
637c478bdstevel@tonic-gate
647c478bdstevel@tonic-gate/*
657c478bdstevel@tonic-gate * PM support
667c478bdstevel@tonic-gate */
677c478bdstevel@tonic-gatetypedef struct usbprn_power  {
687c478bdstevel@tonic-gate	/* device busy accounting */
697c478bdstevel@tonic-gate	int		usbprn_pm_busy;
707c478bdstevel@tonic-gate	uint8_t		usbprn_wakeup_enabled;
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate	/* this is the bit mask of the power states that device has */
737c478bdstevel@tonic-gate	uint8_t		usbprn_pwr_states;
747c478bdstevel@tonic-gate
757c478bdstevel@tonic-gate	/* wakeup and power transistion capabilites of an interface */
767c478bdstevel@tonic-gate	uint8_t		usbprn_pm_capabilities;
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate	uint8_t		usbprn_current_power;
797c478bdstevel@tonic-gate} usbprn_power_t;
807c478bdstevel@tonic-gate
817c478bdstevel@tonic-gate
827c478bdstevel@tonic-gate/*
837c478bdstevel@tonic-gate * State structure
847c478bdstevel@tonic-gate */
857c478bdstevel@tonic-gatetypedef struct usbprn_state {
867c478bdstevel@tonic-gate	dev_info_t	*usbprn_dip;		/* per-device info handle */
877c478bdstevel@tonic-gate	int		usbprn_dev_state;	/* USB device state */
887c478bdstevel@tonic-gate	kmutex_t	usbprn_mutex;		/* for general locking */
897c478bdstevel@tonic-gate	int		usbprn_instance;	/* instance number */
907c478bdstevel@tonic-gate	int		usbprn_flags;
917c478bdstevel@tonic-gate
927c478bdstevel@tonic-gate	usb_client_dev_data_t *usbprn_dev_data;	/* registration data */
937c478bdstevel@tonic-gate
947c478bdstevel@tonic-gate	size_t		usbprn_max_bulk_xfer_size;	/* max txfer size */
957c478bdstevel@tonic-gate	char		*usbprn_device_id;	/* Device id string */
967c478bdstevel@tonic-gate	int		usbprn_device_id_len;	/* Device id length */
977c478bdstevel@tonic-gate
987c478bdstevel@tonic-gate	/* serialize access */
997c478bdstevel@tonic-gate	usb_serialization_t usbprn_ser_acc;
1007c478bdstevel@tonic-gate	usb_serialization_t usbprn_write_acc;
1017c478bdstevel@tonic-gate	usb_serialization_t usbprn_dev_acc;
1027c478bdstevel@tonic-gate
1037c478bdstevel@tonic-gate	/* mblk_t that contains the data to be sent */
1047c478bdstevel@tonic-gate	mblk_t		*usbprn_bulk_mp;
1057c478bdstevel@tonic-gate
1067c478bdstevel@tonic-gate	struct	buf	*usbprn_bp;		/* Buffer ptr for strategy */
1077c478bdstevel@tonic-gate
1087c478bdstevel@tonic-gate	usb_pipe_handle_t usbprn_def_ph;	/* default pipe handle */
1097c478bdstevel@tonic-gate
1107c478bdstevel@tonic-gate	usbprn_ps_t	usbprn_bulk_out;	/* bulk out info */
1117c478bdstevel@tonic-gate	usbprn_ps_t	usbprn_bulk_in;		/* bulk in info */
1127c478bdstevel@tonic-gate
1137c478bdstevel@tonic-gate	usb_log_handle_t usbprn_log_handle;	/* log handle */
1147c478bdstevel@tonic-gate	usb_cfg_descr_t usbprn_config_descr;	/* config desc */
1157c478bdstevel@tonic-gate	usb_if_descr_t	 usbprn_if_descr;	/* interface descr */
1167c478bdstevel@tonic-gate
1177c478bdstevel@tonic-gate	char		usbprn_last_status;	/* last port status */
1187c478bdstevel@tonic-gate
1197c478bdstevel@tonic-gate	usbprn_power_t	*usbprn_pm;		/* Power components */
1207c478bdstevel@tonic-gate
1217c478bdstevel@tonic-gate	struct ecpp_transfer_parms usbprn_setparms; /* Set xfer parameters */
1227c478bdstevel@tonic-gate	struct prn_timeouts	usbprn_prn_timeouts;	/* prnio timeouts */
1237c478bdstevel@tonic-gate
1247c478bdstevel@tonic-gate	usb_ugen_hdl_t	usbprn_ugen_hdl;		/* ugen support */
1257c478bdstevel@tonic-gate} usbprn_state_t;
1267c478bdstevel@tonic-gate
1277c478bdstevel@tonic-gate/* warlock directives, stable data */
1287c478bdstevel@tonic-gate_NOTE(MUTEX_PROTECTS_DATA(usbprn_state_t::usbprn_mutex, usbprn_state_t))
1297c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_dip))
1307c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_ugen_hdl))
1317c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_pm))
1327c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_instance))
1337c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_log_handle))
1347c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_if_descr))
1357c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_dev_data))
1367c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_ser_acc))
1377c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_write_acc))
1387c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_dev_acc))
1397c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_def_ph))
1407c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_device_id))
1417c478bdstevel@tonic-gate_NOTE(DATA_READABLE_WITHOUT_LOCK(usbprn_state_t::usbprn_device_id_len))
1427c478bdstevel@tonic-gate_NOTE(SCHEME_PROTECTS_DATA("stable data", usb_pipe_policy))
1437c478bdstevel@tonic-gate_NOTE(SCHEME_PROTECTS_DATA("unshared data", mblk_t))
1447c478bdstevel@tonic-gate_NOTE(SCHEME_PROTECTS_DATA("unshared data", usb_bulk_req))
1457c478bdstevel@tonic-gate
1467c478bdstevel@tonic-gate
1477c478bdstevel@tonic-gate/* Values for usbprn_flags */
1487c478bdstevel@tonic-gate#define	USBPRN_LOCKS_INIT_DONE	0x01	/* locks have been init'ed */
1497c478bdstevel@tonic-gate#define	USBPRN_OPEN		0x02	/* Device is open */
1507c478bdstevel@tonic-gate
1517c478bdstevel@tonic-gate
1527c478bdstevel@tonic-gate/* Macros */
1537c478bdstevel@tonic-gate
1547c478bdstevel@tonic-gate/*
1557c478bdstevel@tonic-gate * Check if it the device is not being closed
1567c478bdstevel@tonic-gate * or not being disconnected or not being suspended
1577c478bdstevel@tonic-gate */
1587c478bdstevel@tonic-gate#define	USBPRN_DEVICE_ACCESS_OK(s) \
1597c478bdstevel@tonic-gate	(((s)->usbprn_flags & USBPRN_OPEN) && \
1607c478bdstevel@tonic-gate	(((s)->usbprn_dev_state == USB_DEV_ONLINE)))
1617c478bdstevel@tonic-gate
1627c478bdstevel@tonic-gate/* Check if the pipes are idle or closed */
1637c478bdstevel@tonic-gate#define	USBPRN_PIPES_BUSY(s) \
1647c478bdstevel@tonic-gate	(((s)->usbprn_default.ps_flags != USBPRN_PS_IDLE) || \
1657c478bdstevel@tonic-gate	((s)->usbprn_bulk_out.ps_flags != USBPRN_PS_IDLE) || \
1667c478bdstevel@tonic-gate	((s)->usbprn_bulk_in.ps_flags != USBPRN_PS_IDLE))
1677c478bdstevel@tonic-gate
1687c478bdstevel@tonic-gate/*
1697c478bdstevel@tonic-gate * Debug message Masks
1707c478bdstevel@tonic-gate */
1717c478bdstevel@tonic-gate#define	PRINT_MASK_ATTA		0x00000001	/* attach/detach */
1727c478bdstevel@tonic-gate#define	PRINT_MASK_OPEN		0x00000002
1737c478bdstevel@tonic-gate#define	PRINT_MASK_CLOSE	0x00000004
1747c478bdstevel@tonic-gate#define	PRINT_MASK_EVENTS	0x00000008
1757c478bdstevel@tonic-gate#define	PRINT_MASK_PM		0x00000010
1767c478bdstevel@tonic-gate#define	PRINT_MASK_CPR		0x00000020
1777c478bdstevel@tonic-gate#define	PRINT_MASK_ALL		0xFFFFFFFF
1787c478bdstevel@tonic-gate
1797c478bdstevel@tonic-gate/* log message breakup */
1807c478bdstevel@tonic-gate#define	USBPRN_PRINT_MAXLINE	80
1817c478bdstevel@tonic-gate
1827c478bdstevel@tonic-gate/* max device id length */
1837c478bdstevel@tonic-gate#define	USBPRN_MAX_DEVICE_ID_LENGTH	1024
1847c478bdstevel@tonic-gate
1857c478bdstevel@tonic-gate/* ugen support */
1867c478bdstevel@tonic-gate#define	USBPRN_MINOR_UGEN_BITS_MASK	0xff
1877c478bdstevel@tonic-gate#define	USBPRN_MINOR_INSTANCE_SHIFT	8
1887c478bdstevel@tonic-gate#define	USBPRN_MINOR_INSTANCE_MASK	~USBPRN_MINOR_UGEN_BITS_MASK
1897c478bdstevel@tonic-gate#define	USBPRN_MINOR_TO_INSTANCE(minor) \
1907c478bdstevel@tonic-gate	(((minor) & USBPRN_MINOR_INSTANCE_MASK) >> \
1917c478bdstevel@tonic-gate	USBPRN_MINOR_INSTANCE_SHIFT)
1927c478bdstevel@tonic-gate
1937c478bdstevel@tonic-gate
1947c478bdstevel@tonic-gate#ifdef __cplusplus
1957c478bdstevel@tonic-gate}
1967c478bdstevel@tonic-gate#endif
1977c478bdstevel@tonic-gate
1987c478bdstevel@tonic-gate#endif	/* _SYS_USB_USBPRN_H */
199