1527c1e56SGreg Kroah-Hartman /* SPDX-License-Identifier: BSD-3-Clause */ 20ca1268eSLucy McCoy /* 30ca1268eSLucy McCoy usa67msg.h 40ca1268eSLucy McCoy 50ca1268eSLucy McCoy Copyright (c) 1998-2007 InnoSys Incorporated. All Rights Reserved 60ca1268eSLucy McCoy This file is available under a BSD-style copyright 70ca1268eSLucy McCoy 80ca1268eSLucy McCoy Keyspan USB Async Firmware to run on Anchor FX1 90ca1268eSLucy McCoy 100ca1268eSLucy McCoy Redistribution and use in source and binary forms, with or without 110ca1268eSLucy McCoy modification, are permitted provided that the following conditions are 120ca1268eSLucy McCoy met: 130ca1268eSLucy McCoy 140ca1268eSLucy McCoy 1. Redistributions of source code must retain this licence text 150ca1268eSLucy McCoy without modification, this list of conditions, and the following 160ca1268eSLucy McCoy disclaimer. The following copyright notice must appear immediately at 170ca1268eSLucy McCoy the beginning of all source files: 180ca1268eSLucy McCoy 190ca1268eSLucy McCoy Copyright (c) 1998-2007 InnoSys Incorporated. All Rights Reserved 200ca1268eSLucy McCoy 210ca1268eSLucy McCoy This file is available under a BSD-style copyright 220ca1268eSLucy McCoy 230ca1268eSLucy McCoy 2. Redistributions in binary form must reproduce the above copyright 240ca1268eSLucy McCoy notice, this list of conditions and the following disclaimer in the 250ca1268eSLucy McCoy documentation and/or other materials provided with the distribution. 260ca1268eSLucy McCoy 270ca1268eSLucy McCoy 3. The name of InnoSys Incorprated may not be used to endorse or promote 280ca1268eSLucy McCoy products derived from this software without specific prior written 290ca1268eSLucy McCoy permission. 300ca1268eSLucy McCoy 310ca1268eSLucy McCoy THIS SOFTWARE IS PROVIDED BY INNOSYS CORP. ``AS IS'' AND ANY EXPRESS OR 320ca1268eSLucy McCoy IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 330ca1268eSLucy McCoy OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 340ca1268eSLucy McCoy NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 350ca1268eSLucy McCoy INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 360ca1268eSLucy McCoy (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 370ca1268eSLucy McCoy SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 380ca1268eSLucy McCoy CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 390ca1268eSLucy McCoy LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 400ca1268eSLucy McCoy OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 410ca1268eSLucy McCoy SUCH DAMAGE. 420ca1268eSLucy McCoy 430ca1268eSLucy McCoy Fourth revision: This message format supports the USA28XG 440ca1268eSLucy McCoy 450ca1268eSLucy McCoy Buffer formats for RX/TX data messages are not defined by 460ca1268eSLucy McCoy a structure, but are described here: 470ca1268eSLucy McCoy 480ca1268eSLucy McCoy USB OUT (host -> USAxx, transmit) messages contain a 490ca1268eSLucy McCoy REQUEST_ACK indicator (set to 0xff to request an ACK at the 500ca1268eSLucy McCoy completion of transmit; 0x00 otherwise), followed by data: 510ca1268eSLucy McCoy 520ca1268eSLucy McCoy RQSTACK DAT DAT DAT ... 530ca1268eSLucy McCoy 540ca1268eSLucy McCoy with a total data length of up to 63. 550ca1268eSLucy McCoy 560ca1268eSLucy McCoy USB IN (USAxx -> host, receive) messages begin with a status 570ca1268eSLucy McCoy byte in which the 0x80 bit is either: 580ca1268eSLucy McCoy 590ca1268eSLucy McCoy (a) 0x80 bit clear 600ca1268eSLucy McCoy indicates that the bytes following it are all data 610ca1268eSLucy McCoy bytes: 620ca1268eSLucy McCoy 630ca1268eSLucy McCoy STAT DATA DATA DATA DATA DATA ... 640ca1268eSLucy McCoy 650ca1268eSLucy McCoy for a total of up to 63 DATA bytes, 660ca1268eSLucy McCoy 670ca1268eSLucy McCoy or: 680ca1268eSLucy McCoy 690ca1268eSLucy McCoy (b) 0x80 bit set 700ca1268eSLucy McCoy indiates that the bytes following alternate data and 710ca1268eSLucy McCoy status bytes: 720ca1268eSLucy McCoy 730ca1268eSLucy McCoy STAT DATA STAT DATA STAT DATA STAT DATA ... 740ca1268eSLucy McCoy 750ca1268eSLucy McCoy for a total of up to 32 DATA bytes. 760ca1268eSLucy McCoy 770ca1268eSLucy McCoy The valid bits in the STAT bytes are: 780ca1268eSLucy McCoy 790ca1268eSLucy McCoy OVERRUN 0x02 800ca1268eSLucy McCoy PARITY 0x04 810ca1268eSLucy McCoy FRAMING 0x08 820ca1268eSLucy McCoy BREAK 0x10 830ca1268eSLucy McCoy 840ca1268eSLucy McCoy Notes: 850ca1268eSLucy McCoy 860ca1268eSLucy McCoy (1) The OVERRUN bit can appear in either (a) or (b) format 870ca1268eSLucy McCoy messages, but the but the PARITY/FRAMING/BREAK bits 880ca1268eSLucy McCoy only appear in (b) format messages. 890ca1268eSLucy McCoy (2) For the host to determine the exact point at which the 900ca1268eSLucy McCoy overrun occurred (to identify the point in the data 910ca1268eSLucy McCoy stream at which the data was lost), it needs to count 920ca1268eSLucy McCoy 128 characters, starting at the first character of the 930ca1268eSLucy McCoy message in which OVERRUN was reported; the lost character(s) 940ca1268eSLucy McCoy would have been received between the 128th and 129th 950ca1268eSLucy McCoy characters. 960ca1268eSLucy McCoy (3) An RX data message in which the first byte has 0x80 clear 970ca1268eSLucy McCoy serves as a "break off" indicator. 980ca1268eSLucy McCoy 990ca1268eSLucy McCoy revision history: 1000ca1268eSLucy McCoy 1010ca1268eSLucy McCoy 1999feb10 add reportHskiaChanges to allow us to ignore them 1020ca1268eSLucy McCoy 1999feb10 add txAckThreshold for fast+loose throughput enhancement 1030ca1268eSLucy McCoy 1999mar30 beef up support for RX error reporting 1040ca1268eSLucy McCoy 1999apr14 add resetDataToggle to control message 1050ca1268eSLucy McCoy 2000jan04 merge with usa17msg.h 1060ca1268eSLucy McCoy 2000jun01 add extended BSD-style copyright text 1070ca1268eSLucy McCoy 2001jul05 change message format to improve OVERRUN case 1080ca1268eSLucy McCoy 2002jun05 update copyright date, improve comments 1090ca1268eSLucy McCoy 2006feb06 modify for FX1 chip 1100ca1268eSLucy McCoy 1110ca1268eSLucy McCoy */ 1120ca1268eSLucy McCoy 1130ca1268eSLucy McCoy #ifndef __USA67MSG__ 1140ca1268eSLucy McCoy #define __USA67MSG__ 1150ca1268eSLucy McCoy 1160ca1268eSLucy McCoy 1170ca1268eSLucy McCoy // all things called "ControlMessage" are sent on the 'control' endpoint 1180ca1268eSLucy McCoy 1190ca1268eSLucy McCoy typedef struct keyspan_usa67_portControlMessage 1200ca1268eSLucy McCoy { 1210ca1268eSLucy McCoy u8 port; // 0 or 1 (selects port) 1220ca1268eSLucy McCoy /* 1230ca1268eSLucy McCoy there are three types of "commands" sent in the control message: 1240ca1268eSLucy McCoy 1250ca1268eSLucy McCoy 1. configuration changes which must be requested by setting 1260ca1268eSLucy McCoy the corresponding "set" flag (and should only be requested 1270ca1268eSLucy McCoy when necessary, to reduce overhead on the device): 1280ca1268eSLucy McCoy */ 1290ca1268eSLucy McCoy u8 setClocking, // host requests baud rate be set 1300ca1268eSLucy McCoy baudLo, // host does baud divisor calculation 1310ca1268eSLucy McCoy baudHi, // baudHi is only used for first port (gives lower rates) 1320ca1268eSLucy McCoy externalClock_txClocking, 1330ca1268eSLucy McCoy // 0=internal, other=external 1340ca1268eSLucy McCoy 1350ca1268eSLucy McCoy setLcr, // host requests lcr be set 1360ca1268eSLucy McCoy lcr, // use PARITY, STOPBITS, DATABITS below 1370ca1268eSLucy McCoy 1380ca1268eSLucy McCoy setFlowControl, // host requests flow control be set 1390ca1268eSLucy McCoy ctsFlowControl, // 1=use CTS flow control, 0=don't 1400ca1268eSLucy McCoy xonFlowControl, // 1=use XON/XOFF flow control, 0=don't 1410ca1268eSLucy McCoy xonChar, // specified in current character format 1420ca1268eSLucy McCoy xoffChar, // specified in current character format 1430ca1268eSLucy McCoy 1440ca1268eSLucy McCoy setTxTriState_setRts, 1450ca1268eSLucy McCoy // host requests TX tri-state be set 1460ca1268eSLucy McCoy txTriState_rts, // 1=active (normal), 0=tristate (off) 1470ca1268eSLucy McCoy 1480ca1268eSLucy McCoy setHskoa_setDtr, 1490ca1268eSLucy McCoy // host requests HSKOA output be set 1500ca1268eSLucy McCoy hskoa_dtr, // 1=on, 0=off 1510ca1268eSLucy McCoy 1520ca1268eSLucy McCoy setPrescaler, // host requests prescalar be set (default: 13) 1530ca1268eSLucy McCoy prescaler; // specified as N/8; values 8-ff are valid 1540ca1268eSLucy McCoy // must be set any time internal baud rate is set; 1550ca1268eSLucy McCoy // must not be set when external clocking is used 1560ca1268eSLucy McCoy 1570ca1268eSLucy McCoy /* 1580ca1268eSLucy McCoy 3. configuration data which is simply used as is (no overhead, 1590ca1268eSLucy McCoy but must be specified correctly in every host message). 1600ca1268eSLucy McCoy */ 1610ca1268eSLucy McCoy u8 forwardingLength, // forward when this number of chars available 1620ca1268eSLucy McCoy reportHskiaChanges_dsrFlowControl, 1630ca1268eSLucy McCoy // 1=normal; 0=ignore external clock 1640ca1268eSLucy McCoy // 1=use DSR flow control, 0=don't 1650ca1268eSLucy McCoy txAckThreshold, // 0=not allowed, 1=normal, 2-255 deliver ACK faster 1660ca1268eSLucy McCoy loopbackMode; // 0=no loopback, 1=loopback enabled 1670ca1268eSLucy McCoy 1680ca1268eSLucy McCoy /* 1690ca1268eSLucy McCoy 4. commands which are flags only; these are processed in order 1700ca1268eSLucy McCoy (so that, e.g., if both _txOn and _txOff flags are set, the 1710ca1268eSLucy McCoy port ends in a TX_OFF state); any non-zero value is respected 1720ca1268eSLucy McCoy */ 1730ca1268eSLucy McCoy u8 _txOn, // enable transmitting (and continue if there's data) 1740ca1268eSLucy McCoy _txOff, // stop transmitting 1750ca1268eSLucy McCoy txFlush, // toss outbound data 1760ca1268eSLucy McCoy txBreak, // turn on break (cleared by _txOn) 1770ca1268eSLucy McCoy rxOn, // turn on receiver 1780ca1268eSLucy McCoy rxOff, // turn off receiver 1790ca1268eSLucy McCoy rxFlush, // toss inbound data 1800ca1268eSLucy McCoy rxForward, // forward all inbound data, NOW (as if fwdLen==1) 1810ca1268eSLucy McCoy returnStatus, // return current status (even if it hasn't changed) 1820ca1268eSLucy McCoy resetDataToggle;// reset data toggle state to DATA0 1830ca1268eSLucy McCoy 1840ca1268eSLucy McCoy } keyspan_usa67_portControlMessage; 1850ca1268eSLucy McCoy 1860ca1268eSLucy McCoy // defines for bits in lcr 1870ca1268eSLucy McCoy #define USA_DATABITS_5 0x00 1880ca1268eSLucy McCoy #define USA_DATABITS_6 0x01 1890ca1268eSLucy McCoy #define USA_DATABITS_7 0x02 1900ca1268eSLucy McCoy #define USA_DATABITS_8 0x03 1910ca1268eSLucy McCoy #define STOPBITS_5678_1 0x00 // 1 stop bit for all byte sizes 1920ca1268eSLucy McCoy #define STOPBITS_5_1p5 0x04 // 1.5 stop bits for 5-bit byte 1930ca1268eSLucy McCoy #define STOPBITS_678_2 0x04 // 2 stop bits for 6/7/8-bit byte 1940ca1268eSLucy McCoy #define USA_PARITY_NONE 0x00 1950ca1268eSLucy McCoy #define USA_PARITY_ODD 0x08 1960ca1268eSLucy McCoy #define USA_PARITY_EVEN 0x18 1970ca1268eSLucy McCoy #define PARITY_1 0x28 1980ca1268eSLucy McCoy #define PARITY_0 0x38 1990ca1268eSLucy McCoy 2000ca1268eSLucy McCoy // all things called "StatusMessage" are sent on the status endpoint 2010ca1268eSLucy McCoy 2020ca1268eSLucy McCoy typedef struct keyspan_usa67_portStatusMessage // one for each port 2030ca1268eSLucy McCoy { 2040ca1268eSLucy McCoy u8 port, // 0=first, 1=second, other=see below 2050ca1268eSLucy McCoy hskia_cts, // reports HSKIA pin 2060ca1268eSLucy McCoy gpia_dcd, // reports GPIA pin 2070ca1268eSLucy McCoy _txOff, // port has been disabled (by host) 2080ca1268eSLucy McCoy _txXoff, // port is in XOFF state (either host or RX XOFF) 2090ca1268eSLucy McCoy txAck, // indicates a TX message acknowledgement 2100ca1268eSLucy McCoy rxEnabled, // as configured by rxOn/rxOff 1=on, 0=off 2110ca1268eSLucy McCoy controlResponse;// 1=a control message has been processed 2120ca1268eSLucy McCoy } keyspan_usa67_portStatusMessage; 2130ca1268eSLucy McCoy 2140ca1268eSLucy McCoy // bits in RX data message when STAT byte is included 2150ca1268eSLucy McCoy #define RXERROR_OVERRUN 0x02 2160ca1268eSLucy McCoy #define RXERROR_PARITY 0x04 2170ca1268eSLucy McCoy #define RXERROR_FRAMING 0x08 2180ca1268eSLucy McCoy #define RXERROR_BREAK 0x10 2190ca1268eSLucy McCoy 2200ca1268eSLucy McCoy typedef struct keyspan_usa67_globalControlMessage 2210ca1268eSLucy McCoy { 2220ca1268eSLucy McCoy u8 port, // 3 2230ca1268eSLucy McCoy sendGlobalStatus, // 2=request for two status responses 2240ca1268eSLucy McCoy resetStatusToggle, // 1=reset global status toggle 2250ca1268eSLucy McCoy resetStatusCount; // a cycling value 2260ca1268eSLucy McCoy } keyspan_usa67_globalControlMessage; 2270ca1268eSLucy McCoy 2280ca1268eSLucy McCoy typedef struct keyspan_usa67_globalStatusMessage 2290ca1268eSLucy McCoy { 2300ca1268eSLucy McCoy u8 port, // 3 2310ca1268eSLucy McCoy sendGlobalStatus, // from request, decremented 2320ca1268eSLucy McCoy resetStatusCount; // as in request 2330ca1268eSLucy McCoy } keyspan_usa67_globalStatusMessage; 2340ca1268eSLucy McCoy 2350ca1268eSLucy McCoy typedef struct keyspan_usa67_globalDebugMessage 2360ca1268eSLucy McCoy { 2370ca1268eSLucy McCoy u8 port, // 2 2380ca1268eSLucy McCoy a, 2390ca1268eSLucy McCoy b, 2400ca1268eSLucy McCoy c, 2410ca1268eSLucy McCoy d; 2420ca1268eSLucy McCoy } keyspan_usa67_globalDebugMessage; 2430ca1268eSLucy McCoy 2440ca1268eSLucy McCoy // ie: the maximum length of an FX1 endpoint buffer 2450ca1268eSLucy McCoy #define MAX_DATA_LEN 64 2460ca1268eSLucy McCoy 2470ca1268eSLucy McCoy // update status approx. 60 times a second (16.6666 ms) 2480ca1268eSLucy McCoy #define STATUS_UPDATE_INTERVAL 16 2490ca1268eSLucy McCoy 2500ca1268eSLucy McCoy // status rationing tuning value (each port gets checked each n ms) 2510ca1268eSLucy McCoy #define STATUS_RATION 10 2520ca1268eSLucy McCoy 2530ca1268eSLucy McCoy #endif 2540ca1268eSLucy McCoy 2550ca1268eSLucy McCoy 256