xref: /illumos-gate/usr/src/uts/sun4u/sys/rmc_comm_dp.h (revision 270993a9)
17c478bd9Sstevel@tonic-gate /*
28d96d5b3Sjroberts  * CDDL HEADER START
38d96d5b3Sjroberts  *
48d96d5b3Sjroberts  * The contents of this file are subject to the terms of the
58d96d5b3Sjroberts  * Common Development and Distribution License (the "License").
68d96d5b3Sjroberts  * You may not use this file except in compliance with the License.
78d96d5b3Sjroberts  *
88d96d5b3Sjroberts  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98d96d5b3Sjroberts  * or http://www.opensolaris.org/os/licensing.
108d96d5b3Sjroberts  * See the License for the specific language governing permissions
118d96d5b3Sjroberts  * and limitations under the License.
128d96d5b3Sjroberts  *
138d96d5b3Sjroberts  * When distributing Covered Code, include this CDDL HEADER in each
148d96d5b3Sjroberts  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158d96d5b3Sjroberts  * If applicable, add the following below this CDDL HEADER, with the
168d96d5b3Sjroberts  * fields enclosed by brackets "[]" replaced with your own identifying
178d96d5b3Sjroberts  * information: Portions Copyright [yyyy] [name of copyright owner]
188d96d5b3Sjroberts  *
198d96d5b3Sjroberts  * CDDL HEADER END
208d96d5b3Sjroberts  */
218d96d5b3Sjroberts 
228d96d5b3Sjroberts /*
23*270993a9Sfw  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_RMC_COMM_DP_H
287c478bd9Sstevel@tonic-gate #define	_SYS_RMC_COMM_DP_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/rmc_comm_lproto.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
367c478bd9Sstevel@tonic-gate extern "C" {
377c478bd9Sstevel@tonic-gate #endif
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * buffer size (used for tx/rx operations)
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate #define	DP_BUFFER_SIZE	2048
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Number of tx/rx buffers. there are 2 (static) buffers: receive buffer and
467c478bd9Sstevel@tonic-gate  * send buffer. These buffers are basically used by the protocol to packetize
477c478bd9Sstevel@tonic-gate  * a message to be sent OR to collect data received from the serial device.
487c478bd9Sstevel@tonic-gate  * Currently, we just need two for send and receive operations respectively
497c478bd9Sstevel@tonic-gate  * since there is only one request/response session per time (i.e. a new
507c478bd9Sstevel@tonic-gate  * session is not started until the previous one has not finished)
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate #define	DP_BUFFER_COUNT		2
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #define	DP_TX_BUFFER		0
557c478bd9Sstevel@tonic-gate #define	DP_RX_BUFFER		1
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * Tx/Rx buffers.
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate typedef struct dp_buffer {
617c478bd9Sstevel@tonic-gate 	boolean_t in_use;
627c478bd9Sstevel@tonic-gate 	uint8_t buf[DP_BUFFER_SIZE];
637c478bd9Sstevel@tonic-gate } dp_buffer_t;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * Data structure used to collect data from the serial device and to
677c478bd9Sstevel@tonic-gate  * assemble protocol packets
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * The possible states the message receiver can be in:
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate #define	WAITING_FOR_SYNC	0
747c478bd9Sstevel@tonic-gate #define	WAITING_FOR_SYNC_ESC	1
757c478bd9Sstevel@tonic-gate #define	WAITING_FOR_HDR		2
767c478bd9Sstevel@tonic-gate #define	RECEIVING_HDR		3
777c478bd9Sstevel@tonic-gate #define	RECEIVING_HDR_ESC	4
787c478bd9Sstevel@tonic-gate #define	RECEIVING_BODY		5
797c478bd9Sstevel@tonic-gate #define	RECEIVING_BODY_ESC	6
807c478bd9Sstevel@tonic-gate #define	N_RX_STATES		7
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * This is the structure passed between the message receiver state routines.
847c478bd9Sstevel@tonic-gate  * It keeps track of all the state of a message that is in the process of
857c478bd9Sstevel@tonic-gate  * being received.
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate typedef struct dp_packet {
887c478bd9Sstevel@tonic-gate 	uint8_t rx_state;	/* Current state of receive engine. */
897c478bd9Sstevel@tonic-gate 	uint8_t *inbuf;		/* Input characters to be processed. */
907c478bd9Sstevel@tonic-gate 	int16_t inbuflen;	/* Number of input characters. */
917c478bd9Sstevel@tonic-gate 	uint8_t *buf;		/* Buffer used to receive current message. */
927c478bd9Sstevel@tonic-gate 	int16_t bufpos;		/* Position in buffer. */
937c478bd9Sstevel@tonic-gate 	int16_t full_length;	/* Full length of this message. */
947c478bd9Sstevel@tonic-gate } dp_packet_t;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * message data structure used to send/receive data
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate typedef struct dp_message {
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	uint8_t   msg_type;	/* message type */
1037c478bd9Sstevel@tonic-gate 	uint8_t  *msg_buf;	/* message buffer */
1047c478bd9Sstevel@tonic-gate 	uint16_t  msg_bufsiz;	/* size of the buffer */
1057c478bd9Sstevel@tonic-gate 	int16_t   msg_msglen;	/* message length */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate } dp_message_t;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * structure used by the protocol to send (and, eventually re-send...)
1117c478bd9Sstevel@tonic-gate  * messages to the remote side. It keeps the status of the data transfer
1127c478bd9Sstevel@tonic-gate  * (message sent, reply received, etc.). It is also used to match
1137c478bd9Sstevel@tonic-gate  * request/response
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate typedef struct dp_req_resp {
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	uint8_t		flags;		/* status of the data transfer */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define	MSG_ERROR 	0x01
1217c478bd9Sstevel@tonic-gate #define	MSG_SENT 	0x02
1227c478bd9Sstevel@tonic-gate #define	MSG_ACKED 	0x04
1237c478bd9Sstevel@tonic-gate #define	MSG_REPLY_RXED	0x08
1247c478bd9Sstevel@tonic-gate #define	MSG_NAKED	0x10
1257c478bd9Sstevel@tonic-gate #define	MSG_RESET	0x20
1267c478bd9Sstevel@tonic-gate #define	MSG_SENT_BP	0x40
1277c478bd9Sstevel@tonic-gate #define	MSG_RXED_BP	0x80
1287c478bd9Sstevel@tonic-gate 
129*270993a9Sfw 	int		error_status;   /* error code */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	uint8_t		retries_left;   /* number of retries left */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	kcondvar_t  	cv_wait_reply[1];	/* cv variable used to signal */
1347c478bd9Sstevel@tonic-gate 						/* threads waiting for a */
1357c478bd9Sstevel@tonic-gate 						/* reply */
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	dp_message_t	request;	/* request buffer */
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	dp_message_t	response;	/* response buffer */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate } dp_req_resp_t;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate  * interrupt handler prototype (asynchronous messages notification)
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate typedef uint_t (*rmc_comm_intrfunc_t)(caddr_t);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate  * data structure used to deal with asynchronous notification (requests)
1517c478bd9Sstevel@tonic-gate  * from the remote side
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate typedef struct dp_msg_intr {
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	rmc_comm_intrfunc_t	intr_handler;	/* interrupt handler */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	ddi_softintr_t		intr_id;	/* soft intr. id */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	uint8_t			intr_msg_type;	/* message type */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	caddr_t			intr_arg;	/* message buffer containing */
1627c478bd9Sstevel@tonic-gate 						/* the expected message type */
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	kmutex_t		*intr_lock;	/* for state flag below */
1657c478bd9Sstevel@tonic-gate 	uint_t			*intr_state;	/* interrupt handler state */
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate } dp_msg_intr_t;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate  * data protocol structure
1717c478bd9Sstevel@tonic-gate  */
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate typedef struct rmc_comm_dp_state {
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/*
1767c478bd9Sstevel@tonic-gate 	 * data protcol mutex (initialized using <dp_iblk>)
1777c478bd9Sstevel@tonic-gate 	 */
1787c478bd9Sstevel@tonic-gate 	kmutex_t		dp_mutex[1];
1797c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t	dp_iblk;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	boolean_t	data_link_ok;	/* tells whether the data link has */
1827c478bd9Sstevel@tonic-gate 					/* has been established */
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	boolean_t	pending_request;	/* tells if a request is */
1857c478bd9Sstevel@tonic-gate 						/* already being processed */
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	uint8_t		last_tx_seqid;	/* sequence ID of last message */
1887c478bd9Sstevel@tonic-gate 					/* transmitted */
1897c478bd9Sstevel@tonic-gate 	uint8_t		last_rx_seqid;  /* sequence ID of last message */
1907c478bd9Sstevel@tonic-gate 					/* received */
1917c478bd9Sstevel@tonic-gate 	uint8_t		last_rx_ack;    /* last message acknowledged by */
1927c478bd9Sstevel@tonic-gate 					/* remote side */
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	timeout_id_t	timer_link_setup;	/* timer used to set up the */
1957c478bd9Sstevel@tonic-gate 						/* data link at regular */
1967c478bd9Sstevel@tonic-gate 						/* intervals when the link is */
1977c478bd9Sstevel@tonic-gate 						/* down */
1987c478bd9Sstevel@tonic-gate 	timeout_id_t	timer_delay_ack;	/* timer used to wait a 'bit' */
1997c478bd9Sstevel@tonic-gate 						/* before acknowledging a */
2007c478bd9Sstevel@tonic-gate 						/* received message. In the */
2017c478bd9Sstevel@tonic-gate 						/* meantime a request can be */
2027c478bd9Sstevel@tonic-gate 						/* sent from this side and, */
2037c478bd9Sstevel@tonic-gate 						/* hence, acnowledge that */
2047c478bd9Sstevel@tonic-gate 						/* message */
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	kcondvar_t	cv_ok_to_send[1];	/* cv variable used to wait */
2077c478bd9Sstevel@tonic-gate 						/* until it is possible to */
2087c478bd9Sstevel@tonic-gate 						/* send the request (no */
2097c478bd9Sstevel@tonic-gate 						/* pending request */
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	dp_packet_t	dp_packet;		/* used to assemble protocol */
2127c478bd9Sstevel@tonic-gate 						/* packet from data received */
2137c478bd9Sstevel@tonic-gate 						/* from the serial device */
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	dp_req_resp_t	req_resp;		/* request/response data */
2167c478bd9Sstevel@tonic-gate 						/* structure */
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	dp_msg_intr_t	msg_intr;		/* messages for which layered */
2197c478bd9Sstevel@tonic-gate 						/* drivers have registered */
2207c478bd9Sstevel@tonic-gate 						/* for an async notification */
2217c478bd9Sstevel@tonic-gate 						/* (soft.intr.) */
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	dp_buffer_t	dp_buffers[DP_BUFFER_COUNT]; /* protocol buffer  */
2247c478bd9Sstevel@tonic-gate 						/* pool used for    */
2257c478bd9Sstevel@tonic-gate 						/* tx/rx operations */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	/* statistical information */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	uint16_t	reset_cnt;
2307c478bd9Sstevel@tonic-gate 	uint16_t	nak_cnt;
2317c478bd9Sstevel@tonic-gate 	uint16_t	start_cnt;
2327c478bd9Sstevel@tonic-gate 	uint16_t	stack_cnt;
2337c478bd9Sstevel@tonic-gate 	uint16_t	retries_cnt;
2347c478bd9Sstevel@tonic-gate 	uint16_t	crcerr_cnt;
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate } rmc_comm_dp_state_t;
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate #endif
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate #endif	/* _SYS_RMC_COMM_DP_H */
243