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 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_USB_HCDI_H 27 #define _SYS_USB_HCDI_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/genconsole.h> 36 #include <sys/usb/usba/usba_types.h> 37 38 /* 39 * HCD ops structure 40 * 41 * - this structure defines all entry points into HCD 42 * 43 * - all client driver USBAI functions that require HCD 44 * involvement go through this ops table 45 * 46 * - at HCD attach time, the HCD ops are passed to 47 * to the USBA through usba_hcdi_attach() 48 * 49 * some of these ops implement the semantics of the corresponding 50 * USBAI interfaces. Refer to usbai.h for detailed description 51 */ 52 #define HCDI_OPS_VERSION_0 0 53 #define HCDI_OPS_VERSION_1 1 54 #define HCDI_OPS_VERSION HCDI_OPS_VERSION_1 55 56 typedef struct usba_hcdi_ops { 57 int usba_hcdi_ops_version; /* implementation version */ 58 59 dev_info_t *usba_hcdi_dip; /* HCD's devinfo ptr */ 60 61 /* can this hcd support pm? */ 62 int (*usba_hcdi_pm_support)(dev_info_t *dip); 63 64 /* 65 * usba_hcdi_pipe_open: 66 * implements the semantics of usb_pipe_open() 67 * USBA allocate the pipe_handle which contains 68 * pipe_policy and endpoint pointers 69 */ 70 int (*usba_hcdi_pipe_open)( 71 usba_pipe_handle_data_t *pipe_handle, 72 usb_flags_t usb_flags); 73 74 /* 75 * close a pipe 76 */ 77 int (*usba_hcdi_pipe_close)( 78 usba_pipe_handle_data_t *pipe_handle, 79 usb_flags_t usb_flags); 80 81 /* 82 * pipe management 83 */ 84 int (*usba_hcdi_pipe_reset)( 85 usba_pipe_handle_data_t *pipe_handle, 86 usb_flags_t usb_flags); 87 88 /* 89 * data transfer management 90 */ 91 int (*usba_hcdi_pipe_ctrl_xfer)( 92 usba_pipe_handle_data_t *pipe_handle, 93 usb_ctrl_req_t *usb_ctrl_req, 94 usb_flags_t usb_flags); 95 96 /* 97 * get HCD limitation on bulk xfer at a time? 98 */ 99 int (*usba_hcdi_bulk_transfer_size)( 100 usba_device_t *usba_device, 101 size_t *size); 102 103 /* 104 * do bulk read/write 105 */ 106 int (*usba_hcdi_pipe_bulk_xfer)( 107 usba_pipe_handle_data_t *pipe_handle, 108 usb_bulk_req_t *usb_bulk_req, 109 usb_flags_t usb_flags); 110 111 /* 112 * do interrupt pipe read/write 113 */ 114 int (*usba_hcdi_pipe_intr_xfer)( 115 usba_pipe_handle_data_t *pipe_handle, 116 usb_intr_req_t *usb_intr_req, 117 usb_flags_t usb_flags); 118 119 /* 120 * stop interrupt pipe polling 121 */ 122 int (*usba_hcdi_pipe_stop_intr_polling)( 123 usba_pipe_handle_data_t *pipe_handle, 124 usb_flags_t usb_flags); 125 126 /* 127 * do isoch pipe read/write 128 */ 129 int (*usba_hcdi_pipe_isoc_xfer)( 130 usba_pipe_handle_data_t *pipe_handle, 131 usb_isoc_req_t *usb_isoc_req, 132 usb_flags_t usb_flags); 133 134 /* 135 * stop isoc pipe polling 136 */ 137 int (*usba_hcdi_pipe_stop_isoc_polling)( 138 usba_pipe_handle_data_t *pipe_handle, 139 usb_flags_t usb_flags); 140 141 /* utility isoc functions */ 142 usb_frame_number_t 143 (*usba_hcdi_get_current_frame_number)( 144 usba_device_t *usba_device); 145 146 uint_t (*usba_hcdi_get_max_isoc_pkts)( 147 usba_device_t *usba_device); 148 149 /* 150 * Initialize OBP support for input 151 */ 152 int (*usba_hcdi_console_input_init)( 153 usba_pipe_handle_data_t *pipe_handle, 154 uchar_t **obp_buf, 155 usb_console_info_impl_t *console_input_info); 156 157 /* 158 * Free resources allocated by usba_hcdi_console_input_init 159 */ 160 int (*usba_hcdi_console_input_fini)( 161 usb_console_info_impl_t *console_input_info); 162 163 /* 164 * Save controller state information 165 */ 166 int (*usba_hcdi_console_input_enter)( 167 usb_console_info_impl_t *console_input_info); 168 169 /* 170 * Read character from controller 171 */ 172 int (*usba_hcdi_console_read)( 173 usb_console_info_impl_t *console_input_info, 174 uint_t *num_characters); 175 176 /* 177 * Restore controller state information 178 */ 179 int (*usba_hcdi_console_input_exit)( 180 usb_console_info_impl_t *console_input_info); 181 182 183 /* 184 * VERSION 1 ops: support for polled output 185 */ 186 int (*usba_hcdi_console_output_init)( 187 usba_pipe_handle_data_t *pipe_handle, 188 usb_console_info_impl_t *console_output_info); 189 190 int (*usba_hcdi_console_output_fini)( 191 usb_console_info_impl_t *console_output_info); 192 193 int (*usba_hcdi_console_output_enter)( 194 usb_console_info_impl_t *console_output_info); 195 196 int (*usba_hcdi_console_write)( 197 usb_console_info_impl_t *console_output_info, 198 uchar_t *buf, 199 uint_t num_characters, 200 uint_t *num_characters_written); 201 202 int (*usba_hcdi_console_output_exit)( 203 usb_console_info_impl_t *console_output_info); 204 } usba_hcdi_ops_t; 205 206 207 /* 208 * callback support: 209 * this function handles all HCD callbacks as follows: 210 * - USB_FLAGS_SLEEP determines whether the client driver made 211 * a synchronous or asynchronous USBAI call 212 * - for synchronous calls, the args are copied into the pipe handle 213 * and the sync cv of the pipe handle is signalled 214 * - for async calls and completion_reason = 0, the normal callback 215 * is invoked 216 * - for async calls and completion_reason != 0, the exception 217 * callback is invoked 218 */ 219 void 220 usba_hcdi_cb(usba_pipe_handle_data_t *ph, 221 usb_opaque_t req, 222 usb_cr_t completion_reason); 223 224 /* 225 * function to duplicate a interrupt/isoc request (for HCD) 226 */ 227 usb_intr_req_t *usba_hcdi_dup_intr_req(dev_info_t *, 228 usb_intr_req_t *, size_t, usb_flags_t); 229 usb_isoc_req_t *usba_hcdi_dup_isoc_req(dev_info_t *, 230 usb_isoc_req_t *, usb_flags_t); 231 232 /* access to private member of requests */ 233 usb_opaque_t usba_hcdi_get_req_private(usb_opaque_t); 234 void usba_hcdi_set_req_private(usb_opaque_t, usb_opaque_t); 235 usba_pipe_handle_data_t * 236 usba_hcdi_get_ph_data(usba_device_t *, uint8_t); 237 238 /* data toggle get and set */ 239 uchar_t usba_hcdi_get_data_toggle(usba_device_t *, uint8_t); 240 void usba_hcdi_set_data_toggle(usba_device_t *, uint8_t, uchar_t); 241 242 /* 243 * HCD Nexus driver support: 244 */ 245 246 /* 247 * hcd_ops allocator/deallocator 248 * USBA allocates the usba_hcdi_ops so we can easily handle 249 * versioning 250 */ 251 usba_hcdi_ops_t *usba_alloc_hcdi_ops(); 252 void usba_free_hcdi_ops(usba_hcdi_ops_t *); 253 254 /* 255 * Argument structure for usba_hcdi_register 256 */ 257 typedef struct usba_hcdi_register_args { 258 uint_t usba_hcdi_register_version; 259 dev_info_t *usba_hcdi_register_dip; 260 usba_hcdi_ops_t *usba_hcdi_register_ops; 261 ddi_dma_attr_t *usba_hcdi_register_dma_attr; 262 ddi_iblock_cookie_t usba_hcdi_register_iblock_cookie; 263 264 } usba_hcdi_register_args_t; 265 266 #define HCDI_REGISTER_VERS_0 0 267 #define HCDI_REGISTER_VERSION HCDI_REGISTER_VERS_0 268 269 270 /* 271 * make this instance known to USBA 272 * 273 * the HCD must initialize the hcdi_ops before calling this function 274 */ 275 int usba_hcdi_register(usba_hcdi_register_args_t *, uint_t); 276 277 /* 278 * detach support 279 */ 280 void usba_hcdi_unregister(dev_info_t *); 281 282 /* 283 * Hotplug kstats named structure 284 * 285 * Number of types of USB transfers 286 */ 287 #define USB_N_COUNT_KSTATS 4 288 289 typedef struct hcdi_hotplug_stats { 290 struct kstat_named hcdi_hotplug_total_success; 291 struct kstat_named hcdi_hotplug_success; 292 struct kstat_named hcdi_hotplug_total_failure; 293 struct kstat_named hcdi_hotplug_failure; 294 struct kstat_named hcdi_device_count; 295 } hcdi_hotplug_stats_t; 296 297 /* 298 * USB error kstats named structure 299 */ 300 typedef struct hcdi_error_stats { 301 /* transport completion codes */ 302 struct kstat_named cc_crc; 303 struct kstat_named cc_bitstuffing; 304 struct kstat_named cc_data_toggle_mm; 305 struct kstat_named cc_stall; 306 struct kstat_named cc_dev_not_resp; 307 struct kstat_named cc_pid_checkfailure; 308 struct kstat_named cc_unexp_pid; 309 struct kstat_named cc_data_overrun; 310 struct kstat_named cc_data_underrun; 311 struct kstat_named cc_buffer_overrun; 312 struct kstat_named cc_buffer_underrun; 313 struct kstat_named cc_timeout; 314 struct kstat_named cc_not_accessed; 315 struct kstat_named cc_no_resources; 316 struct kstat_named cc_unspecified_err; 317 struct kstat_named cc_stopped_polling; 318 struct kstat_named cc_pipe_closing; 319 struct kstat_named cc_pipe_reset; 320 struct kstat_named cc_not_supported; 321 struct kstat_named cc_flushed; 322 323 #ifdef NOTYETNEEDED 324 /* USBA function return values */ 325 struct kstat_named hcdi_usb_failure; 326 struct kstat_named hcdi_usb_no_resources; 327 struct kstat_named hcdi_usb_no_bandwidth; 328 struct kstat_named hcdi_usb_pipe_reserved; 329 struct kstat_named hcdi_usb_pipe_unshareable; 330 struct kstat_named hcdi_usb_not_supported; 331 struct kstat_named hcdi_usb_pipe_error; 332 struct kstat_named hcdi_usb_pipe_busy; 333 #endif 334 } hcdi_error_stats_t; 335 336 /* 337 * hcdi kstat defines 338 * XXX this needs to be a function 339 */ 340 #define HCDI_HOTPLUG_STATS(hcdi) ((hcdi)->hcdi_hotplug_stats) 341 #define HCDI_HOTPLUG_STATS_DATA(hcdi) \ 342 ((hcdi_hotplug_stats_t *)HCDI_HOTPLUG_STATS((hcdi))->ks_data) 343 344 #define HCDI_ERROR_STATS(hcdi) ((hcdi)->hcdi_error_stats) 345 #define HCDI_ERROR_STATS_DATA(hcdi) \ 346 ((hcdi_error_stats_t *)HCDI_ERROR_STATS((hcdi))->ks_data) 347 348 349 #ifdef __cplusplus 350 } 351 #endif 352 353 #endif /* _SYS_USB_HCDI_H */ 354