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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_USB_USBSER_KEYSPAN_VAR_H 28 #define _SYS_USB_USBSER_KEYSPAN_VAR_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * keyspan implementation definitions 34 */ 35 36 #include <sys/types.h> 37 #include <sys/dditypes.h> 38 #include <sys/note.h> 39 40 #include <sys/usb/clients/usbser/usbser_dsdi.h> 41 42 #include <sys/usb/clients/usbser/usbser_keyspan/usa90msg.h> 43 #ifdef KEYSPAN_USA49WLC 44 #include <sys/usb/clients/usbser/usbser_keyspan/usa49msg.h> 45 #endif /* If KEYSPAN_USA49WLC defined */ 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 /* product id */ 52 #define KEYSPAN_USA19HS_PID 0x121 53 #define KEYSPAN_USA49WLC_PID 0x12a 54 55 #define KEYSPAN_MAX_PORT_NUM 4 56 57 /* 58 * forward typedefs needed to resolve recursive header dependencies 59 */ 60 typedef struct keyspan_pre_state keyspan_pre_state_t; 61 typedef struct keyspan_state keyspan_state_t; 62 typedef struct keyspan_port keyspan_port_t; 63 64 #include <sys/usb/clients/usbser/usbser_keyspan/keyspan_pipe.h> 65 66 /* 67 * temporary soft state for pre_attach 68 */ 69 struct keyspan_pre_state { 70 dev_info_t *kb_dip; /* device info */ 71 int kb_instance; /* instance */ 72 usb_client_dev_data_t *kb_dev_data; /* registration data */ 73 usb_log_handle_t kb_lh; /* USBA log handle */ 74 keyspan_pipe_t kb_def_pipe; /* default pipe */ 75 }; 76 77 /* 78 * PM support 79 */ 80 typedef struct keyspan_power { 81 uint8_t pm_wakeup_enabled; /* remote wakeup enabled */ 82 uint8_t pm_pwr_states; /* bit mask of power states */ 83 boolean_t pm_raise_power; /* driver is about to raise power */ 84 uint8_t pm_cur_power; /* current power level */ 85 uint_t pm_busy_cnt; /* number of set_busy requests */ 86 } keyspan_pm_t; 87 88 /* 89 * device specific info structure 90 */ 91 typedef struct keyspan_dev_spec { 92 93 uint16_t id_product; /* product ID value */ 94 uint8_t port_cnt; /* How many ports on the device */ 95 uint8_t ctrl_ep_addr; /* Endpoint used to control the device */ 96 uint8_t stat_ep_addr; /* Endpoint used to get device status */ 97 uint8_t dataout_ep_addr[4]; /* Endpoint used to send data */ 98 99 /* Endpoint used to get data from device */ 100 uint8_t datain_ep_addr[4]; 101 } keyspan_dev_spec_t; 102 103 /* 104 * To support different keyspan adapters, use union type 105 * for different cmd msg format. 106 */ 107 typedef union keyspan_port_ctrl_msg { 108 keyspan_usa19hs_port_ctrl_msg_t usa19hs; 109 #ifdef KEYSPAN_USA49WLC 110 keyspan_usa49_port_ctrl_msg_t usa49; 111 #endif /* If KEYSPAN_USA49WLC defined */ 112 } keyspan_port_ctrl_msg_t; 113 114 /* 115 * To support different keyspan adapters, use union type 116 * for different status msg format. 117 */ 118 typedef union keyspan_port_status_msg { 119 keyspan_usa19hs_port_status_msg_t usa19hs; 120 #ifdef KEYSPAN_USA49WLC 121 keyspan_usa49_port_status_msg_t usa49; 122 #endif /* If KEYSPAN_USA49WLC defined */ 123 } keyspan_port_status_msg_t; 124 125 /* 126 * per device state structure 127 */ 128 struct keyspan_state { 129 kmutex_t ks_mutex; /* structure lock */ 130 dev_info_t *ks_dip; /* device info */ 131 keyspan_port_t *ks_ports; /* per port structs */ 132 keyspan_dev_spec_t ks_dev_spec; /* device specific info */ 133 134 /* 135 * we use semaphore to serialize pipe open/close by different ports. 136 * mutex could be used too, but it causes trouble when warlocking 137 * with USBA: some functions inside usb_pipe_close() wait on cv 138 * 139 * since semaphore is only used for serialization during 140 * open/close and suspend/resume, there is no deadlock hazard 141 */ 142 ksema_t ks_pipes_sema; 143 144 /* 145 * USBA related 146 */ 147 usb_client_dev_data_t *ks_dev_data; /* registration data */ 148 usb_event_t *ks_usb_events; /* usb events */ 149 150 keyspan_pipe_t ks_def_pipe; /* default pipe */ 151 152 /* bulk in pipe for getting device status */ 153 keyspan_pipe_t ks_statin_pipe; 154 155 /* bulk out pipe for sending control cmd to device */ 156 keyspan_pipe_t ks_ctrlout_pipe; 157 158 usb_log_handle_t ks_lh; /* USBA log handle */ 159 int ks_dev_state; /* USB device state */ 160 keyspan_pm_t *ks_pm; /* PM support */ 161 162 }; 163 164 _NOTE(MUTEX_PROTECTS_DATA(keyspan_state::ks_mutex, keyspan_state)) 165 _NOTE(DATA_READABLE_WITHOUT_LOCK(keyspan_state::{ 166 ks_dip 167 ks_dev_data 168 ks_usb_events 169 ks_dev_spec 170 ks_ports 171 ks_def_pipe 172 ks_ctrlout_pipe.pipe_handle 173 ks_statin_pipe.pipe_handle 174 ks_lh 175 ks_pm 176 })) 177 178 /* 179 * per port structure 180 */ 181 struct keyspan_port { 182 kmutex_t kp_mutex; /* structure lock */ 183 keyspan_state_t *kp_ksp; /* back pointer to the state */ 184 char kp_lh_name[16]; /* log handle name */ 185 usb_log_handle_t kp_lh; /* log handle */ 186 uint_t kp_port_num; /* port number */ 187 int kp_state; /* port state */ 188 int kp_flags; /* port flags */ 189 ds_cb_t kp_cb; /* DSD callbacks */ 190 kcondvar_t kp_tx_cv; /* cv to wait for tx completion */ 191 /* 192 * data receipt and transmit 193 */ 194 mblk_t *kp_rx_mp; /* received data */ 195 mblk_t *kp_tx_mp; /* data to transmit */ 196 boolean_t kp_no_more_reads; /* disable reads */ 197 198 /* The control cmd sent to the port */ 199 keyspan_port_ctrl_msg_t kp_ctrl_msg; 200 201 /* status msg of the port */ 202 keyspan_port_status_msg_t kp_status_msg; 203 204 uint_t kp_baud; /* the current baud speed code */ 205 uint8_t kp_lcr; /* the current lcr value */ 206 /* 207 * the current port status, including: rts, dtr, 208 * break, loopback, enable. 209 */ 210 uint8_t kp_status_flag; 211 212 keyspan_pipe_t kp_datain_pipe; /* bulk in data pipe */ 213 keyspan_pipe_t kp_dataout_pipe; /* bulk out data pipe */ 214 215 uint_t kp_read_len; /* max length of bulkin request */ 216 uint_t kp_write_len; /* max length of bulkout request */ 217 }; 218 219 _NOTE(MUTEX_PROTECTS_DATA(keyspan_port::kp_mutex, keyspan_port)) 220 _NOTE(DATA_READABLE_WITHOUT_LOCK(keyspan_port::{ 221 kp_ksp 222 kp_lh 223 kp_port_num 224 kp_read_len 225 kp_write_len 226 kp_cb 227 kp_datain_pipe.pipe_handle 228 kp_datain_pipe.pipe_ep_descr 229 })) 230 231 /* lock relationships */ 232 _NOTE(LOCK_ORDER(keyspan_state::ks_mutex keyspan_port::kp_mutex)) 233 _NOTE(LOCK_ORDER(keyspan_port::kp_mutex keyspan_pipe::pipe_mutex)) 234 235 /* port status flags */ 236 enum { 237 KEYSPAN_PORT_ENABLE = 0x0001, /* port is enabled */ 238 KEYSPAN_PORT_RTS = 0x0002, /* port's rts is set */ 239 KEYSPAN_PORT_DTR = 0x0004, /* port's dtr is set */ 240 KEYSPAN_PORT_TXBREAK = 0x0008, /* port is in TX break mod */ 241 KEYSPAN_PORT_LOOPBACK = 0x0010, /* port is in loopback mod */ 242 243 /* the ctrl cmd sent to this port is responded */ 244 KEYSPAN_PORT_CTRLRESP = 0x0020, 245 KEYSPAN_PORT_RXBREAK = 0x0040 /* port is in RX break mod */ 246 }; 247 248 /* port state */ 249 enum { 250 KEYSPAN_PORT_NOT_INIT = 0, /* port is not initialized */ 251 KEYSPAN_PORT_CLOSED, /* port is closed */ 252 KEYSPAN_PORT_OPENING, /* port is being opened */ 253 KEYSPAN_PORT_OPEN /* port is open */ 254 }; 255 256 /* port flags */ 257 enum { 258 KEYSPAN_PORT_TX_STOPPED = 0x0001 /* transmit not allowed */ 259 }; 260 261 /* various tunables */ 262 enum { 263 KEYSPAN_BULK_TIMEOUT = 3, /* transfer timeout */ 264 KEYSPAN_BULKIN_MAX_LEN = 64, /* bulk in max length */ 265 KEYSPAN_BULKOUT_MAX_LEN = 64, /* bulk out max length */ 266 KEYSPAN_STATIN_MAX_LEN = 16 /* status in max length */ 267 }; 268 269 /* This flag indicates if the firmware already downloaded to the device */ 270 #define KEYSPAN_FW_FLAG 0x8000 271 272 /* Vendor specific ctrl req, used to set/download bytes in the device memory */ 273 #define KEYSPAN_REQ_SET 0xa0 274 275 /* 276 * debug printing masks 277 */ 278 #define DPRINT_ATTACH 0x00000001 279 #define DPRINT_OPEN 0x00000002 280 #define DPRINT_CLOSE 0x00000004 281 #define DPRINT_DEF_PIPE 0x00000010 282 #define DPRINT_IN_PIPE 0x00000020 283 #define DPRINT_OUT_PIPE 0x00000040 284 #define DPRINT_INTR_PIPE 0x00000080 285 #define DPRINT_PIPE_RESET 0x00000100 286 #define DPRINT_IN_DATA 0x00000200 287 #define DPRINT_OUT_DATA 0x00000400 288 #define DPRINT_CTLOP 0x00000800 289 #define DPRINT_HOTPLUG 0x00001000 290 #define DPRINT_PM 0x00002000 291 #define DPRINT_MASK_ALL 0xFFFFFFFF 292 293 /* 294 * misc macros 295 */ 296 #define NELEM(a) (sizeof (a) / sizeof (*(a))) 297 298 /* common DSD functions */ 299 int keyspan_tx_copy_data(keyspan_port_t *, mblk_t *, int); 300 void keyspan_tx_start(keyspan_port_t *, int *); 301 void keyspan_put_tail(mblk_t **, mblk_t *); 302 void keyspan_put_head(mblk_t **, mblk_t *, keyspan_port_t *); 303 304 void keyspan_bulkin_cb(usb_pipe_handle_t, usb_bulk_req_t *); 305 void keyspan_bulkout_cb(usb_pipe_handle_t, usb_bulk_req_t *); 306 307 int keyspan_restore_device(keyspan_state_t *); 308 int keyspan_send_cmd(keyspan_port_t *); 309 310 int keyspan_dev_is_online(keyspan_state_t *); 311 312 313 #ifdef __cplusplus 314 } 315 #endif 316 317 #endif /* _SYS_USB_USBSER_KEYSPAN_VAR_H */ 318