10Sstevel@tonic-gate /* 21121Sjroberts * CDDL HEADER START 31121Sjroberts * 41121Sjroberts * The contents of this file are subject to the terms of the 51121Sjroberts * Common Development and Distribution License (the "License"). 61121Sjroberts * You may not use this file except in compliance with the License. 71121Sjroberts * 81121Sjroberts * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91121Sjroberts * or http://www.opensolaris.org/os/licensing. 101121Sjroberts * See the License for the specific language governing permissions 111121Sjroberts * and limitations under the License. 121121Sjroberts * 131121Sjroberts * When distributing Covered Code, include this CDDL HEADER in each 141121Sjroberts * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151121Sjroberts * If applicable, add the following below this CDDL HEADER, with the 161121Sjroberts * fields enclosed by brackets "[]" replaced with your own identifying 171121Sjroberts * information: Portions Copyright [yyyy] [name of copyright owner] 181121Sjroberts * 191121Sjroberts * CDDL HEADER END 201121Sjroberts */ 211121Sjroberts 221121Sjroberts /* 23*1182Sfw157321 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _SYS_RMC_COMM_DP_H 280Sstevel@tonic-gate #define _SYS_RMC_COMM_DP_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/rmc_comm_lproto.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * buffer size (used for tx/rx operations) 410Sstevel@tonic-gate */ 420Sstevel@tonic-gate #define DP_BUFFER_SIZE 2048 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * Number of tx/rx buffers. there are 2 (static) buffers: receive buffer and 460Sstevel@tonic-gate * send buffer. These buffers are basically used by the protocol to packetize 470Sstevel@tonic-gate * a message to be sent OR to collect data received from the serial device. 480Sstevel@tonic-gate * Currently, we just need two for send and receive operations respectively 490Sstevel@tonic-gate * since there is only one request/response session per time (i.e. a new 500Sstevel@tonic-gate * session is not started until the previous one has not finished) 510Sstevel@tonic-gate */ 520Sstevel@tonic-gate #define DP_BUFFER_COUNT 2 530Sstevel@tonic-gate 540Sstevel@tonic-gate #define DP_TX_BUFFER 0 550Sstevel@tonic-gate #define DP_RX_BUFFER 1 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * Tx/Rx buffers. 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate typedef struct dp_buffer { 610Sstevel@tonic-gate boolean_t in_use; 620Sstevel@tonic-gate uint8_t buf[DP_BUFFER_SIZE]; 630Sstevel@tonic-gate } dp_buffer_t; 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * Data structure used to collect data from the serial device and to 670Sstevel@tonic-gate * assemble protocol packets 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate 700Sstevel@tonic-gate /* 710Sstevel@tonic-gate * The possible states the message receiver can be in: 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate #define WAITING_FOR_SYNC 0 740Sstevel@tonic-gate #define WAITING_FOR_SYNC_ESC 1 750Sstevel@tonic-gate #define WAITING_FOR_HDR 2 760Sstevel@tonic-gate #define RECEIVING_HDR 3 770Sstevel@tonic-gate #define RECEIVING_HDR_ESC 4 780Sstevel@tonic-gate #define RECEIVING_BODY 5 790Sstevel@tonic-gate #define RECEIVING_BODY_ESC 6 800Sstevel@tonic-gate #define N_RX_STATES 7 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * This is the structure passed between the message receiver state routines. 840Sstevel@tonic-gate * It keeps track of all the state of a message that is in the process of 850Sstevel@tonic-gate * being received. 860Sstevel@tonic-gate */ 870Sstevel@tonic-gate typedef struct dp_packet { 880Sstevel@tonic-gate uint8_t rx_state; /* Current state of receive engine. */ 890Sstevel@tonic-gate uint8_t *inbuf; /* Input characters to be processed. */ 900Sstevel@tonic-gate int16_t inbuflen; /* Number of input characters. */ 910Sstevel@tonic-gate uint8_t *buf; /* Buffer used to receive current message. */ 920Sstevel@tonic-gate int16_t bufpos; /* Position in buffer. */ 930Sstevel@tonic-gate int16_t full_length; /* Full length of this message. */ 940Sstevel@tonic-gate } dp_packet_t; 950Sstevel@tonic-gate 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * message data structure used to send/receive data 990Sstevel@tonic-gate */ 1000Sstevel@tonic-gate typedef struct dp_message { 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate uint8_t msg_type; /* message type */ 1030Sstevel@tonic-gate uint8_t *msg_buf; /* message buffer */ 1040Sstevel@tonic-gate uint16_t msg_bufsiz; /* size of the buffer */ 1050Sstevel@tonic-gate int16_t msg_msglen; /* message length */ 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate } dp_message_t; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * structure used by the protocol to send (and, eventually re-send...) 1110Sstevel@tonic-gate * messages to the remote side. It keeps the status of the data transfer 1120Sstevel@tonic-gate * (message sent, reply received, etc.). It is also used to match 1130Sstevel@tonic-gate * request/response 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate typedef struct dp_req_resp { 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate uint8_t flags; /* status of the data transfer */ 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate #define MSG_ERROR 0x01 1210Sstevel@tonic-gate #define MSG_SENT 0x02 1220Sstevel@tonic-gate #define MSG_ACKED 0x04 1230Sstevel@tonic-gate #define MSG_REPLY_RXED 0x08 1240Sstevel@tonic-gate #define MSG_NAKED 0x10 1250Sstevel@tonic-gate #define MSG_RESET 0x20 1260Sstevel@tonic-gate #define MSG_SENT_BP 0x40 1270Sstevel@tonic-gate #define MSG_RXED_BP 0x80 1280Sstevel@tonic-gate 129*1182Sfw157321 int error_status; /* error code */ 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate uint8_t retries_left; /* number of retries left */ 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate kcondvar_t cv_wait_reply[1]; /* cv variable used to signal */ 1340Sstevel@tonic-gate /* threads waiting for a */ 1350Sstevel@tonic-gate /* reply */ 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate dp_message_t request; /* request buffer */ 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate dp_message_t response; /* response buffer */ 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate } dp_req_resp_t; 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate /* 1450Sstevel@tonic-gate * interrupt handler prototype (asynchronous messages notification) 1460Sstevel@tonic-gate */ 1470Sstevel@tonic-gate typedef uint_t (*rmc_comm_intrfunc_t)(caddr_t); 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate /* 1500Sstevel@tonic-gate * data structure used to deal with asynchronous notification (requests) 1510Sstevel@tonic-gate * from the remote side 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate typedef struct dp_msg_intr { 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate rmc_comm_intrfunc_t intr_handler; /* interrupt handler */ 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate ddi_softintr_t intr_id; /* soft intr. id */ 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate uint8_t intr_msg_type; /* message type */ 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate caddr_t intr_arg; /* message buffer containing */ 1620Sstevel@tonic-gate /* the expected message type */ 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate kmutex_t *intr_lock; /* for state flag below */ 1650Sstevel@tonic-gate uint_t *intr_state; /* interrupt handler state */ 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate } dp_msg_intr_t; 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate /* 1700Sstevel@tonic-gate * data protocol structure 1710Sstevel@tonic-gate */ 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate typedef struct rmc_comm_dp_state { 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate /* 1760Sstevel@tonic-gate * data protcol mutex (initialized using <dp_iblk>) 1770Sstevel@tonic-gate */ 1780Sstevel@tonic-gate kmutex_t dp_mutex[1]; 1790Sstevel@tonic-gate ddi_iblock_cookie_t dp_iblk; 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate boolean_t data_link_ok; /* tells whether the data link has */ 1820Sstevel@tonic-gate /* has been established */ 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate boolean_t pending_request; /* tells if a request is */ 1850Sstevel@tonic-gate /* already being processed */ 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate uint8_t last_tx_seqid; /* sequence ID of last message */ 1880Sstevel@tonic-gate /* transmitted */ 1890Sstevel@tonic-gate uint8_t last_rx_seqid; /* sequence ID of last message */ 1900Sstevel@tonic-gate /* received */ 1910Sstevel@tonic-gate uint8_t last_rx_ack; /* last message acknowledged by */ 1920Sstevel@tonic-gate /* remote side */ 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate timeout_id_t timer_link_setup; /* timer used to set up the */ 1950Sstevel@tonic-gate /* data link at regular */ 1960Sstevel@tonic-gate /* intervals when the link is */ 1970Sstevel@tonic-gate /* down */ 1980Sstevel@tonic-gate timeout_id_t timer_delay_ack; /* timer used to wait a 'bit' */ 1990Sstevel@tonic-gate /* before acknowledging a */ 2000Sstevel@tonic-gate /* received message. In the */ 2010Sstevel@tonic-gate /* meantime a request can be */ 2020Sstevel@tonic-gate /* sent from this side and, */ 2030Sstevel@tonic-gate /* hence, acnowledge that */ 2040Sstevel@tonic-gate /* message */ 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate kcondvar_t cv_ok_to_send[1]; /* cv variable used to wait */ 2070Sstevel@tonic-gate /* until it is possible to */ 2080Sstevel@tonic-gate /* send the request (no */ 2090Sstevel@tonic-gate /* pending request */ 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate dp_packet_t dp_packet; /* used to assemble protocol */ 2120Sstevel@tonic-gate /* packet from data received */ 2130Sstevel@tonic-gate /* from the serial device */ 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate dp_req_resp_t req_resp; /* request/response data */ 2160Sstevel@tonic-gate /* structure */ 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate dp_msg_intr_t msg_intr; /* messages for which layered */ 2190Sstevel@tonic-gate /* drivers have registered */ 2200Sstevel@tonic-gate /* for an async notification */ 2210Sstevel@tonic-gate /* (soft.intr.) */ 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate dp_buffer_t dp_buffers[DP_BUFFER_COUNT]; /* protocol buffer */ 2240Sstevel@tonic-gate /* pool used for */ 2250Sstevel@tonic-gate /* tx/rx operations */ 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate /* statistical information */ 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate uint16_t reset_cnt; 2300Sstevel@tonic-gate uint16_t nak_cnt; 2310Sstevel@tonic-gate uint16_t start_cnt; 2320Sstevel@tonic-gate uint16_t stack_cnt; 2330Sstevel@tonic-gate uint16_t retries_cnt; 2340Sstevel@tonic-gate uint16_t crcerr_cnt; 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate } rmc_comm_dp_state_t; 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate #ifdef __cplusplus 2390Sstevel@tonic-gate } 2400Sstevel@tonic-gate #endif 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate #endif /* _SYS_RMC_COMM_DP_H */ 243