17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 528cdc3d7Sszhou * Common Development and Distribution License (the "License"). 628cdc3d7Sszhou * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*d29f5a71Szhigang lu - Sun Microsystems - Beijing China * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_USB_USBSER_DSDI_H 277c478bd9Sstevel@tonic-gate #define _SYS_USB_USBSER_DSDI_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * USB-to-serial device-specific driver interface (DSDI) 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 367c478bd9Sstevel@tonic-gate #include <sys/usb/usba.h> 377c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usbai_private.h> 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifdef __cplusplus 407c478bd9Sstevel@tonic-gate extern "C" { 417c478bd9Sstevel@tonic-gate #endif 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate typedef void *ds_hdl_t; /* DSD device handler */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * interrupt emulation callbacks 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate typedef struct ds_cb { 497c478bd9Sstevel@tonic-gate void (*cb_tx)(caddr_t); /* transmit callback */ 507c478bd9Sstevel@tonic-gate void (*cb_rx)(caddr_t); /* receive callback */ 517c478bd9Sstevel@tonic-gate void (*cb_status)(caddr_t); /* status change callback */ 527c478bd9Sstevel@tonic-gate caddr_t cb_arg; /* callback argument */ 537c478bd9Sstevel@tonic-gate } ds_cb_t; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate typedef struct ds_port_params ds_port_params_t; /* see below */ 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate typedef struct ds_attach_info { 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * passed to DSD: 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate dev_info_t *ai_dip; /* devinfo */ 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * these event callbacks should be registered by DSD 647c478bd9Sstevel@tonic-gate * using usb_register_event_cbs() 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate usb_event_t *ai_usb_events; 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * returned by DSD: 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate ds_hdl_t *ai_hdl; /* handle to be used by GSD in other calls */ 717c478bd9Sstevel@tonic-gate uint_t *ai_port_cnt; /* number of ports */ 727c478bd9Sstevel@tonic-gate } ds_attach_info_t; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * device operations used by Generic Serial Driver (GSD) 767c478bd9Sstevel@tonic-gate * 777c478bd9Sstevel@tonic-gate * ops returning int should return USB_SUCCESS on successful completion 787c478bd9Sstevel@tonic-gate * or appropriate USB_* error code in case of failure 797c478bd9Sstevel@tonic-gate * 807c478bd9Sstevel@tonic-gate * ops can block unless otherwise indicated 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate typedef struct ds_ops { 837c478bd9Sstevel@tonic-gate int ds_version; /* structure version */ 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* 867c478bd9Sstevel@tonic-gate * configuration operations 877c478bd9Sstevel@tonic-gate * ------------------------ 887c478bd9Sstevel@tonic-gate * 897c478bd9Sstevel@tonic-gate * attach/detach device instance, called from GSD attach(9E)/detach(9E) 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate int (*ds_attach)(ds_attach_info_t *aip); 927c478bd9Sstevel@tonic-gate void (*ds_detach)(ds_hdl_t); 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate /* 957c478bd9Sstevel@tonic-gate * register/unregister interrupt callbacks for the given port 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate int (*ds_register_cb)(ds_hdl_t, uint_t port_num, ds_cb_t *cb); 987c478bd9Sstevel@tonic-gate void (*ds_unregister_cb)(ds_hdl_t, uint_t port_num); 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* 1017c478bd9Sstevel@tonic-gate * open/close port 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate int (*ds_open_port)(ds_hdl_t, uint_t port_num); 1047c478bd9Sstevel@tonic-gate int (*ds_close_port)(ds_hdl_t, uint_t port_num); 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * power management 1087c478bd9Sstevel@tonic-gate * ---------------- 1097c478bd9Sstevel@tonic-gate * 1107c478bd9Sstevel@tonic-gate * set power level of the component; 1117c478bd9Sstevel@tonic-gate * DSD should set new_state to the resulting USB device state 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate int (*ds_usb_power)(ds_hdl_t, int comp, int level, int *new_state); 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * CPR suspend/resume 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate int (*ds_suspend)(ds_hdl_t); 1197c478bd9Sstevel@tonic-gate int (*ds_resume)(ds_hdl_t); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * USB device disconnect/reconnect 1237c478bd9Sstevel@tonic-gate */ 1247c478bd9Sstevel@tonic-gate int (*ds_disconnect)(ds_hdl_t); 1257c478bd9Sstevel@tonic-gate int (*ds_reconnect)(ds_hdl_t); 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate /* 1287c478bd9Sstevel@tonic-gate * standard UART operations 1297c478bd9Sstevel@tonic-gate * ------------------------ 1307c478bd9Sstevel@tonic-gate * 1317c478bd9Sstevel@tonic-gate * set one or more port parameters: baud rate, parity, 1327c478bd9Sstevel@tonic-gate * stop bits, character size, xon/xoff char, flow control 1337c478bd9Sstevel@tonic-gate */ 1347c478bd9Sstevel@tonic-gate int (*ds_set_port_params)(ds_hdl_t, uint_t port_num, 1357c478bd9Sstevel@tonic-gate ds_port_params_t *tp); 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * set modem controls: each bit set to 1 in 'mask' will be set to the 1397c478bd9Sstevel@tonic-gate * value of corresponding bit in 'val'; other bits are not affected 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate int (*ds_set_modem_ctl)(ds_hdl_t, uint_t port_num, 1427c478bd9Sstevel@tonic-gate int mask, int val); 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate * get modem control/status: values of bits that correspond 1467c478bd9Sstevel@tonic-gate * to those set to 1 in 'mask' are returned in 'valp' 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate int (*ds_get_modem_ctl)(ds_hdl_t, uint_t port_num, 1497c478bd9Sstevel@tonic-gate int mask, int *valp); 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* 1527c478bd9Sstevel@tonic-gate * set/clear break ('ctl' is DS_ON/DS_OFF) 1537c478bd9Sstevel@tonic-gate */ 1547c478bd9Sstevel@tonic-gate int (*ds_break_ctl)(ds_hdl_t, uint_t port_num, int ctl); 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * set/clear internal loopback ('ctl' is DS_ON/DS_OFF) 1587c478bd9Sstevel@tonic-gate */ 1597c478bd9Sstevel@tonic-gate int (*ds_loopback)(ds_hdl_t, uint_t port_num, int ctl); 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* 1627c478bd9Sstevel@tonic-gate * data xfer 1637c478bd9Sstevel@tonic-gate * --------- 1647c478bd9Sstevel@tonic-gate * 1657c478bd9Sstevel@tonic-gate * data transmit: DSD is *required* to accept mblk for transfer and 1667c478bd9Sstevel@tonic-gate * return USB_SUCCESS; after which GSD no longer owns the mblk 1677c478bd9Sstevel@tonic-gate */ 1687c478bd9Sstevel@tonic-gate int (*ds_tx)(ds_hdl_t, uint_t port_num, mblk_t *mp); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * data receipt: DSD returns either received data mblk or NULL 1727c478bd9Sstevel@tonic-gate * if no data available. this op must not block as it is intended 1737c478bd9Sstevel@tonic-gate * to be called from is usually called GSD receive callback 1747c478bd9Sstevel@tonic-gate */ 1757c478bd9Sstevel@tonic-gate mblk_t *(*ds_rx)(ds_hdl_t, uint_t port_num); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * stop/start data transmit or/and receive: 1797c478bd9Sstevel@tonic-gate * 'dir' can be an OR of DS_TX and DS_RX; must succeed. 1807c478bd9Sstevel@tonic-gate */ 1817c478bd9Sstevel@tonic-gate void (*ds_stop)(ds_hdl_t, uint_t port_num, int dir); 1827c478bd9Sstevel@tonic-gate void (*ds_start)(ds_hdl_t, uint_t port_num, int dir); 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* 1857c478bd9Sstevel@tonic-gate * flush FIFOs: 'dir' can be an OR of DS_TX and DS_RX, 1867c478bd9Sstevel@tonic-gate * affecting transmit and received FIFO respectively 1877c478bd9Sstevel@tonic-gate */ 1887c478bd9Sstevel@tonic-gate int (*ds_fifo_flush)(ds_hdl_t, uint_t port_num, int dir); 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate /* 1917c478bd9Sstevel@tonic-gate * drain (wait until empty) output FIFO 1927c478bd9Sstevel@tonic-gate * 1937c478bd9Sstevel@tonic-gate * return failure if the FIFO does not get empty after at least 1947c478bd9Sstevel@tonic-gate * 'timeout' seconds (zero timeout means wait forever) 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate int (*ds_fifo_drain)(ds_hdl_t, uint_t port_num, int timeout); 19728cdc3d7Sszhou 19828cdc3d7Sszhou /* V1 ops for polled I/O */ 19928cdc3d7Sszhou usb_pipe_handle_t (*ds_out_pipe)(ds_hdl_t, uint_t port_num); 20028cdc3d7Sszhou usb_pipe_handle_t (*ds_in_pipe)(ds_hdl_t, uint_t port_num); 2017c478bd9Sstevel@tonic-gate } ds_ops_t; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate /* 2047c478bd9Sstevel@tonic-gate * ds_version 2057c478bd9Sstevel@tonic-gate */ 2067c478bd9Sstevel@tonic-gate enum { 2077c478bd9Sstevel@tonic-gate DS_OPS_VERSION_V0 = 0, 20828cdc3d7Sszhou DS_OPS_VERSION_V1 = 1, 20928cdc3d7Sszhou DS_OPS_VERSION = DS_OPS_VERSION_V1 2107c478bd9Sstevel@tonic-gate }; 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate /* 2137c478bd9Sstevel@tonic-gate * parameter type 2147c478bd9Sstevel@tonic-gate */ 2157c478bd9Sstevel@tonic-gate typedef enum { 2167c478bd9Sstevel@tonic-gate DS_PARAM_BAUD, /* baud rate */ 2177c478bd9Sstevel@tonic-gate DS_PARAM_PARITY, /* parity */ 2187c478bd9Sstevel@tonic-gate DS_PARAM_STOPB, /* stop bits */ 2197c478bd9Sstevel@tonic-gate DS_PARAM_CHARSZ, /* char size */ 2207c478bd9Sstevel@tonic-gate DS_PARAM_XON_XOFF, /* xon/xoff chars */ 2217c478bd9Sstevel@tonic-gate DS_PARAM_FLOW_CTL /* flow control */ 2227c478bd9Sstevel@tonic-gate } ds_port_param_type_t; 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * a single param entry, union used to pass various data types 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate typedef struct ds_port_param_entry { 2287c478bd9Sstevel@tonic-gate ds_port_param_type_t param; /* parameter */ 2297c478bd9Sstevel@tonic-gate union { 2307c478bd9Sstevel@tonic-gate uint_t ui; 2317c478bd9Sstevel@tonic-gate uchar_t uc[4]; 2327c478bd9Sstevel@tonic-gate } val; /* parameter value(s) */ 2337c478bd9Sstevel@tonic-gate } ds_port_param_entry_t; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * port parameter array 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate struct ds_port_params { 2397c478bd9Sstevel@tonic-gate ds_port_param_entry_t *tp_entries; /* entry array */ 2407c478bd9Sstevel@tonic-gate int tp_cnt; /* entry count */ 2417c478bd9Sstevel@tonic-gate }; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate /* 2447c478bd9Sstevel@tonic-gate * direction (ds_fifo_flush, ds_fifo_drain) 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate enum { 2477c478bd9Sstevel@tonic-gate DS_TX = 0x01, /* transmit direction */ 2487c478bd9Sstevel@tonic-gate DS_RX = 0x02 /* receive direction */ 2497c478bd9Sstevel@tonic-gate }; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate /* 2527c478bd9Sstevel@tonic-gate * on/off (ds_break_ctl, ds_loopback) 2537c478bd9Sstevel@tonic-gate */ 2547c478bd9Sstevel@tonic-gate enum { 2557c478bd9Sstevel@tonic-gate DS_OFF, 2567c478bd9Sstevel@tonic-gate DS_ON 2577c478bd9Sstevel@tonic-gate }; 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate /* 2607c478bd9Sstevel@tonic-gate * input error codes, returned by DSD in an M_BREAK message 2617c478bd9Sstevel@tonic-gate */ 2627c478bd9Sstevel@tonic-gate enum { 2637c478bd9Sstevel@tonic-gate DS_PARITY_ERR = 0x01, /* parity error */ 2647c478bd9Sstevel@tonic-gate DS_FRAMING_ERR = 0x02, /* framing error */ 2657c478bd9Sstevel@tonic-gate DS_OVERRUN_ERR = 0x03, /* data overrun */ 2667c478bd9Sstevel@tonic-gate DS_BREAK_ERR = 0x04 /* break detected */ 2677c478bd9Sstevel@tonic-gate }; 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2707c478bd9Sstevel@tonic-gate } 2717c478bd9Sstevel@tonic-gate #endif 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate #endif /* _SYS_USB_USBSER_DSDI_H */ 274