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_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 int (*usba_hcdi_get_current_frame_number)( 143 usba_device_t *usba_device, 144 usb_frame_number_t *frame_number); 145 146 int (*usba_hcdi_get_max_isoc_pkts)( 147 usba_device_t *usba_device, 148 uint_t *max_isoc_pkts_per_request); 149 150 /* 151 * Initialize OBP support for input 152 */ 153 int (*usba_hcdi_console_input_init)( 154 usba_pipe_handle_data_t *pipe_handle, 155 uchar_t **obp_buf, 156 usb_console_info_impl_t *console_input_info); 157 158 /* 159 * Free resources allocated by usba_hcdi_console_input_init 160 */ 161 int (*usba_hcdi_console_input_fini)( 162 usb_console_info_impl_t *console_input_info); 163 164 /* 165 * Save controller state information 166 */ 167 int (*usba_hcdi_console_input_enter)( 168 usb_console_info_impl_t *console_input_info); 169 170 /* 171 * Read character from controller 172 */ 173 int (*usba_hcdi_console_read)( 174 usb_console_info_impl_t *console_input_info, 175 uint_t *num_characters); 176 177 /* 178 * Restore controller state information 179 */ 180 int (*usba_hcdi_console_input_exit)( 181 usb_console_info_impl_t *console_input_info); 182 183 184 /* 185 * VERSION 1 ops: support for polled output 186 */ 187 int (*usba_hcdi_console_output_init)( 188 usba_pipe_handle_data_t *pipe_handle, 189 usb_console_info_impl_t *console_output_info); 190 191 int (*usba_hcdi_console_output_fini)( 192 usb_console_info_impl_t *console_output_info); 193 194 int (*usba_hcdi_console_output_enter)( 195 usb_console_info_impl_t *console_output_info); 196 197 int (*usba_hcdi_console_write)( 198 usb_console_info_impl_t *console_output_info, 199 uchar_t *buf, 200 uint_t num_characters, 201 uint_t *num_characters_written); 202 203 int (*usba_hcdi_console_output_exit)( 204 usb_console_info_impl_t *console_output_info); 205 } usba_hcdi_ops_t; 206 207 208 /* 209 * callback support: 210 * this function handles all HCD callbacks as follows: 211 * - USB_FLAGS_SLEEP determines whether the client driver made 212 * a synchronous or asynchronous USBAI call 213 * - for synchronous calls, the args are copied into the pipe handle 214 * and the sync cv of the pipe handle is signalled 215 * - for async calls and completion_reason = 0, the normal callback 216 * is invoked 217 * - for async calls and completion_reason != 0, the exception 218 * callback is invoked 219 */ 220 void 221 usba_hcdi_cb(usba_pipe_handle_data_t *ph, 222 usb_opaque_t req, 223 usb_cr_t completion_reason); 224 225 /* 226 * function to duplicate a interrupt/isoc request (for HCD) 227 */ 228 usb_intr_req_t *usba_hcdi_dup_intr_req(dev_info_t *, 229 usb_intr_req_t *, size_t, usb_flags_t); 230 usb_isoc_req_t *usba_hcdi_dup_isoc_req(dev_info_t *, 231 usb_isoc_req_t *, usb_flags_t); 232 233 /* access to private member of requests */ 234 usb_opaque_t usba_hcdi_get_req_private(usb_opaque_t); 235 void usba_hcdi_set_req_private(usb_opaque_t, usb_opaque_t); 236 usba_pipe_handle_data_t * 237 usba_hcdi_get_ph_data(usba_device_t *, uint8_t); 238 239 /* data toggle get and set */ 240 uchar_t usba_hcdi_get_data_toggle(usba_device_t *, uint8_t); 241 void usba_hcdi_set_data_toggle(usba_device_t *, uint8_t, uchar_t); 242 243 /* 244 * HCD Nexus driver support: 245 */ 246 247 /* 248 * hcd_ops allocator/deallocator 249 * USBA allocates the usba_hcdi_ops so we can easily handle 250 * versioning 251 */ 252 usba_hcdi_ops_t *usba_alloc_hcdi_ops(); 253 void usba_free_hcdi_ops(usba_hcdi_ops_t *); 254 255 /* 256 * Argument structure for usba_hcdi_register 257 */ 258 typedef struct usba_hcdi_register_args { 259 uint_t usba_hcdi_register_version; 260 dev_info_t *usba_hcdi_register_dip; 261 usba_hcdi_ops_t *usba_hcdi_register_ops; 262 ddi_dma_attr_t *usba_hcdi_register_dma_attr; 263 ddi_iblock_cookie_t usba_hcdi_register_iblock_cookie; 264 265 } usba_hcdi_register_args_t; 266 267 #define HCDI_REGISTER_VERS_0 0 268 #define HCDI_REGISTER_VERSION HCDI_REGISTER_VERS_0 269 270 271 /* 272 * make this instance known to USBA 273 * 274 * the HCD must initialize the hcdi_ops before calling this function 275 */ 276 int usba_hcdi_register(usba_hcdi_register_args_t *, uint_t); 277 278 /* 279 * detach support 280 */ 281 void usba_hcdi_unregister(dev_info_t *); 282 283 /* 284 * Hotplug kstats named structure 285 * 286 * Number of types of USB transfers 287 */ 288 #define USB_N_COUNT_KSTATS 4 289 290 typedef struct hcdi_hotplug_stats { 291 struct kstat_named hcdi_hotplug_total_success; 292 struct kstat_named hcdi_hotplug_success; 293 struct kstat_named hcdi_hotplug_total_failure; 294 struct kstat_named hcdi_hotplug_failure; 295 struct kstat_named hcdi_device_count; 296 } hcdi_hotplug_stats_t; 297 298 /* 299 * USB error kstats named structure 300 */ 301 typedef struct hcdi_error_stats { 302 /* transport completion codes */ 303 struct kstat_named cc_crc; 304 struct kstat_named cc_bitstuffing; 305 struct kstat_named cc_data_toggle_mm; 306 struct kstat_named cc_stall; 307 struct kstat_named cc_dev_not_resp; 308 struct kstat_named cc_pid_checkfailure; 309 struct kstat_named cc_unexp_pid; 310 struct kstat_named cc_data_overrun; 311 struct kstat_named cc_data_underrun; 312 struct kstat_named cc_buffer_overrun; 313 struct kstat_named cc_buffer_underrun; 314 struct kstat_named cc_timeout; 315 struct kstat_named cc_not_accessed; 316 struct kstat_named cc_no_resources; 317 struct kstat_named cc_unspecified_err; 318 struct kstat_named cc_stopped_polling; 319 struct kstat_named cc_pipe_closing; 320 struct kstat_named cc_pipe_reset; 321 struct kstat_named cc_not_supported; 322 struct kstat_named cc_flushed; 323 324 #ifdef NOTYETNEEDED 325 /* USBA function return values */ 326 struct kstat_named hcdi_usb_failure; 327 struct kstat_named hcdi_usb_no_resources; 328 struct kstat_named hcdi_usb_no_bandwidth; 329 struct kstat_named hcdi_usb_pipe_reserved; 330 struct kstat_named hcdi_usb_pipe_unshareable; 331 struct kstat_named hcdi_usb_not_supported; 332 struct kstat_named hcdi_usb_pipe_error; 333 struct kstat_named hcdi_usb_pipe_busy; 334 #endif 335 } hcdi_error_stats_t; 336 337 /* 338 * hcdi kstat defines 339 * XXX this needs to be a function 340 */ 341 #define HCDI_HOTPLUG_STATS(hcdi) ((hcdi)->hcdi_hotplug_stats) 342 #define HCDI_HOTPLUG_STATS_DATA(hcdi) \ 343 ((hcdi_hotplug_stats_t *)HCDI_HOTPLUG_STATS((hcdi))->ks_data) 344 345 #define HCDI_ERROR_STATS(hcdi) ((hcdi)->hcdi_error_stats) 346 #define HCDI_ERROR_STATS_DATA(hcdi) \ 347 ((hcdi_error_stats_t *)HCDI_ERROR_STATS((hcdi))->ks_data) 348 349 350 #ifdef __cplusplus 351 } 352 #endif 353 354 #endif /* _SYS_USB_HCDI_H */ 355