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_USBSER_DSDI_H 27 #define _SYS_USB_USBSER_DSDI_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 /* 32 * USB-to-serial device-specific driver interface (DSDI) 33 */ 34 35 #include <sys/types.h> 36 #include <sys/dditypes.h> 37 #include <sys/usb/usba.h> 38 #include <sys/usb/usba/usbai_private.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 typedef void *ds_hdl_t; /* DSD device handler */ 45 46 /* 47 * interrupt emulation callbacks 48 */ 49 typedef struct ds_cb { 50 void (*cb_tx)(caddr_t); /* transmit callback */ 51 void (*cb_rx)(caddr_t); /* receive callback */ 52 void (*cb_status)(caddr_t); /* status change callback */ 53 caddr_t cb_arg; /* callback argument */ 54 } ds_cb_t; 55 56 typedef struct ds_port_params ds_port_params_t; /* see below */ 57 58 typedef struct ds_attach_info { 59 /* 60 * passed to DSD: 61 */ 62 dev_info_t *ai_dip; /* devinfo */ 63 /* 64 * these event callbacks should be registered by DSD 65 * using usb_register_event_cbs() 66 */ 67 usb_event_t *ai_usb_events; 68 /* 69 * returned by DSD: 70 */ 71 ds_hdl_t *ai_hdl; /* handle to be used by GSD in other calls */ 72 uint_t *ai_port_cnt; /* number of ports */ 73 } ds_attach_info_t; 74 75 /* 76 * device operations used by Generic Serial Driver (GSD) 77 * 78 * ops returning int should return USB_SUCCESS on successful completion 79 * or appropriate USB_* error code in case of failure 80 * 81 * ops can block unless otherwise indicated 82 */ 83 typedef struct ds_ops { 84 int ds_version; /* structure version */ 85 86 /* 87 * configuration operations 88 * ------------------------ 89 * 90 * attach/detach device instance, called from GSD attach(9E)/detach(9E) 91 */ 92 int (*ds_attach)(ds_attach_info_t *aip); 93 void (*ds_detach)(ds_hdl_t); 94 95 /* 96 * register/unregister interrupt callbacks for the given port 97 */ 98 int (*ds_register_cb)(ds_hdl_t, uint_t port_num, ds_cb_t *cb); 99 void (*ds_unregister_cb)(ds_hdl_t, uint_t port_num); 100 101 /* 102 * open/close port 103 */ 104 int (*ds_open_port)(ds_hdl_t, uint_t port_num); 105 int (*ds_close_port)(ds_hdl_t, uint_t port_num); 106 107 /* 108 * power management 109 * ---------------- 110 * 111 * set power level of the component; 112 * DSD should set new_state to the resulting USB device state 113 */ 114 int (*ds_usb_power)(ds_hdl_t, int comp, int level, int *new_state); 115 116 /* 117 * CPR suspend/resume 118 */ 119 int (*ds_suspend)(ds_hdl_t); 120 int (*ds_resume)(ds_hdl_t); 121 122 /* 123 * USB device disconnect/reconnect 124 */ 125 int (*ds_disconnect)(ds_hdl_t); 126 int (*ds_reconnect)(ds_hdl_t); 127 128 /* 129 * standard UART operations 130 * ------------------------ 131 * 132 * set one or more port parameters: baud rate, parity, 133 * stop bits, character size, xon/xoff char, flow control 134 */ 135 int (*ds_set_port_params)(ds_hdl_t, uint_t port_num, 136 ds_port_params_t *tp); 137 138 /* 139 * set modem controls: each bit set to 1 in 'mask' will be set to the 140 * value of corresponding bit in 'val'; other bits are not affected 141 */ 142 int (*ds_set_modem_ctl)(ds_hdl_t, uint_t port_num, 143 int mask, int val); 144 145 /* 146 * get modem control/status: values of bits that correspond 147 * to those set to 1 in 'mask' are returned in 'valp' 148 */ 149 int (*ds_get_modem_ctl)(ds_hdl_t, uint_t port_num, 150 int mask, int *valp); 151 152 /* 153 * set/clear break ('ctl' is DS_ON/DS_OFF) 154 */ 155 int (*ds_break_ctl)(ds_hdl_t, uint_t port_num, int ctl); 156 157 /* 158 * set/clear internal loopback ('ctl' is DS_ON/DS_OFF) 159 */ 160 int (*ds_loopback)(ds_hdl_t, uint_t port_num, int ctl); 161 162 /* 163 * data xfer 164 * --------- 165 * 166 * data transmit: DSD is *required* to accept mblk for transfer and 167 * return USB_SUCCESS; after which GSD no longer owns the mblk 168 */ 169 int (*ds_tx)(ds_hdl_t, uint_t port_num, mblk_t *mp); 170 171 /* 172 * data receipt: DSD returns either received data mblk or NULL 173 * if no data available. this op must not block as it is intended 174 * to be called from is usually called GSD receive callback 175 */ 176 mblk_t *(*ds_rx)(ds_hdl_t, uint_t port_num); 177 178 /* 179 * stop/start data transmit or/and receive: 180 * 'dir' can be an OR of DS_TX and DS_RX; must succeed. 181 */ 182 void (*ds_stop)(ds_hdl_t, uint_t port_num, int dir); 183 void (*ds_start)(ds_hdl_t, uint_t port_num, int dir); 184 185 /* 186 * flush FIFOs: 'dir' can be an OR of DS_TX and DS_RX, 187 * affecting transmit and received FIFO respectively 188 */ 189 int (*ds_fifo_flush)(ds_hdl_t, uint_t port_num, int dir); 190 191 /* 192 * drain (wait until empty) output FIFO 193 * 194 * return failure if the FIFO does not get empty after at least 195 * 'timeout' seconds (zero timeout means wait forever) 196 */ 197 int (*ds_fifo_drain)(ds_hdl_t, uint_t port_num, int timeout); 198 199 /* V1 ops for polled I/O */ 200 usb_pipe_handle_t (*ds_out_pipe)(ds_hdl_t, uint_t port_num); 201 usb_pipe_handle_t (*ds_in_pipe)(ds_hdl_t, uint_t port_num); 202 } ds_ops_t; 203 204 /* 205 * ds_version 206 */ 207 enum { 208 DS_OPS_VERSION_V0 = 0, 209 DS_OPS_VERSION_V1 = 1, 210 DS_OPS_VERSION = DS_OPS_VERSION_V1 211 }; 212 213 /* 214 * parameter type 215 */ 216 typedef enum { 217 DS_PARAM_BAUD, /* baud rate */ 218 DS_PARAM_PARITY, /* parity */ 219 DS_PARAM_STOPB, /* stop bits */ 220 DS_PARAM_CHARSZ, /* char size */ 221 DS_PARAM_XON_XOFF, /* xon/xoff chars */ 222 DS_PARAM_FLOW_CTL /* flow control */ 223 } ds_port_param_type_t; 224 225 /* 226 * a single param entry, union used to pass various data types 227 */ 228 typedef struct ds_port_param_entry { 229 ds_port_param_type_t param; /* parameter */ 230 union { 231 uint_t ui; 232 uchar_t uc[4]; 233 } val; /* parameter value(s) */ 234 } ds_port_param_entry_t; 235 236 /* 237 * port parameter array 238 */ 239 struct ds_port_params { 240 ds_port_param_entry_t *tp_entries; /* entry array */ 241 int tp_cnt; /* entry count */ 242 }; 243 244 /* 245 * direction (ds_fifo_flush, ds_fifo_drain) 246 */ 247 enum { 248 DS_TX = 0x01, /* transmit direction */ 249 DS_RX = 0x02 /* receive direction */ 250 }; 251 252 /* 253 * on/off (ds_break_ctl, ds_loopback) 254 */ 255 enum { 256 DS_OFF, 257 DS_ON 258 }; 259 260 /* 261 * input error codes, returned by DSD in an M_BREAK message 262 */ 263 enum { 264 DS_PARITY_ERR = 0x01, /* parity error */ 265 DS_FRAMING_ERR = 0x02, /* framing error */ 266 DS_OVERRUN_ERR = 0x03, /* data overrun */ 267 DS_BREAK_ERR = 0x04 /* break detected */ 268 }; 269 270 #ifdef __cplusplus 271 } 272 #endif 273 274 #endif /* _SYS_USB_USBSER_DSDI_H */ 275