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