18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _HVSI_H
38c2ecf20Sopenharmony_ci#define _HVSI_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#define VS_DATA_PACKET_HEADER           0xff
68c2ecf20Sopenharmony_ci#define VS_CONTROL_PACKET_HEADER        0xfe
78c2ecf20Sopenharmony_ci#define VS_QUERY_PACKET_HEADER          0xfd
88c2ecf20Sopenharmony_ci#define VS_QUERY_RESPONSE_PACKET_HEADER 0xfc
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* control verbs */
118c2ecf20Sopenharmony_ci#define VSV_SET_MODEM_CTL    1 /* to service processor only */
128c2ecf20Sopenharmony_ci#define VSV_MODEM_CTL_UPDATE 2 /* from service processor only */
138c2ecf20Sopenharmony_ci#define VSV_CLOSE_PROTOCOL   3
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* query verbs */
168c2ecf20Sopenharmony_ci#define VSV_SEND_VERSION_NUMBER 1
178c2ecf20Sopenharmony_ci#define VSV_SEND_MODEM_CTL_STATUS 2
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* yes, these masks are not consecutive. */
208c2ecf20Sopenharmony_ci#define HVSI_TSDTR 0x01
218c2ecf20Sopenharmony_ci#define HVSI_TSCD  0x20
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define HVSI_MAX_OUTGOING_DATA 12
248c2ecf20Sopenharmony_ci#define HVSI_VERSION 1
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistruct hvsi_header {
278c2ecf20Sopenharmony_ci	uint8_t  type;
288c2ecf20Sopenharmony_ci	uint8_t  len;
298c2ecf20Sopenharmony_ci	__be16 seqno;
308c2ecf20Sopenharmony_ci} __attribute__((packed));
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct hvsi_data {
338c2ecf20Sopenharmony_ci	struct hvsi_header hdr;
348c2ecf20Sopenharmony_ci	uint8_t  data[HVSI_MAX_OUTGOING_DATA];
358c2ecf20Sopenharmony_ci} __attribute__((packed));
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistruct hvsi_control {
388c2ecf20Sopenharmony_ci	struct hvsi_header hdr;
398c2ecf20Sopenharmony_ci	__be16 verb;
408c2ecf20Sopenharmony_ci	/* optional depending on verb: */
418c2ecf20Sopenharmony_ci	__be32 word;
428c2ecf20Sopenharmony_ci	__be32 mask;
438c2ecf20Sopenharmony_ci} __attribute__((packed));
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistruct hvsi_query {
468c2ecf20Sopenharmony_ci	struct hvsi_header hdr;
478c2ecf20Sopenharmony_ci	__be16 verb;
488c2ecf20Sopenharmony_ci} __attribute__((packed));
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistruct hvsi_query_response {
518c2ecf20Sopenharmony_ci	struct hvsi_header hdr;
528c2ecf20Sopenharmony_ci	__be16 verb;
538c2ecf20Sopenharmony_ci	__be16 query_seqno;
548c2ecf20Sopenharmony_ci	union {
558c2ecf20Sopenharmony_ci		uint8_t  version;
568c2ecf20Sopenharmony_ci		__be32 mctrl_word;
578c2ecf20Sopenharmony_ci	} u;
588c2ecf20Sopenharmony_ci} __attribute__((packed));
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* hvsi lib struct definitions */
618c2ecf20Sopenharmony_ci#define HVSI_INBUF_SIZE		255
628c2ecf20Sopenharmony_cistruct tty_struct;
638c2ecf20Sopenharmony_cistruct hvsi_priv {
648c2ecf20Sopenharmony_ci	unsigned int	inbuf_len;	/* data in input buffer */
658c2ecf20Sopenharmony_ci	unsigned char	inbuf[HVSI_INBUF_SIZE];
668c2ecf20Sopenharmony_ci	unsigned int	inbuf_cur;	/* Cursor in input buffer */
678c2ecf20Sopenharmony_ci	unsigned int	inbuf_pktlen;	/* packet length from cursor */
688c2ecf20Sopenharmony_ci	atomic_t	seqno;		/* packet sequence number */
698c2ecf20Sopenharmony_ci	unsigned int	opened:1;	/* driver opened */
708c2ecf20Sopenharmony_ci	unsigned int	established:1;	/* protocol established */
718c2ecf20Sopenharmony_ci	unsigned int 	is_console:1;	/* used as a kernel console device */
728c2ecf20Sopenharmony_ci	unsigned int	mctrl_update:1;	/* modem control updated */
738c2ecf20Sopenharmony_ci	unsigned short	mctrl;		/* modem control */
748c2ecf20Sopenharmony_ci	struct tty_struct *tty;		/* tty structure */
758c2ecf20Sopenharmony_ci	int (*get_chars)(uint32_t termno, char *buf, int count);
768c2ecf20Sopenharmony_ci	int (*put_chars)(uint32_t termno, const char *buf, int count);
778c2ecf20Sopenharmony_ci	uint32_t	termno;
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* hvsi lib functions */
818c2ecf20Sopenharmony_cistruct hvc_struct;
828c2ecf20Sopenharmony_ciextern void hvsilib_init(struct hvsi_priv *pv,
838c2ecf20Sopenharmony_ci			 int (*get_chars)(uint32_t termno, char *buf, int count),
848c2ecf20Sopenharmony_ci			 int (*put_chars)(uint32_t termno, const char *buf,
858c2ecf20Sopenharmony_ci					  int count),
868c2ecf20Sopenharmony_ci			 int termno, int is_console);
878c2ecf20Sopenharmony_ciextern int hvsilib_open(struct hvsi_priv *pv, struct hvc_struct *hp);
888c2ecf20Sopenharmony_ciextern void hvsilib_close(struct hvsi_priv *pv, struct hvc_struct *hp);
898c2ecf20Sopenharmony_ciextern int hvsilib_read_mctrl(struct hvsi_priv *pv);
908c2ecf20Sopenharmony_ciextern int hvsilib_write_mctrl(struct hvsi_priv *pv, int dtr);
918c2ecf20Sopenharmony_ciextern void hvsilib_establish(struct hvsi_priv *pv);
928c2ecf20Sopenharmony_ciextern int hvsilib_get_chars(struct hvsi_priv *pv, char *buf, int count);
938c2ecf20Sopenharmony_ciextern int hvsilib_put_chars(struct hvsi_priv *pv, const char *buf, int count);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#endif /* _HVSI_H */
96