18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci *  Bluetooth HCI UART driver
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci *  Copyright (C) 2000-2001  Qualcomm Incorporated
78c2ecf20Sopenharmony_ci *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
88c2ecf20Sopenharmony_ci *  Copyright (C) 2004-2005  Marcel Holtmann <marcel@holtmann.org>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef N_HCI
128c2ecf20Sopenharmony_ci#define N_HCI	15
138c2ecf20Sopenharmony_ci#endif
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* Ioctls */
168c2ecf20Sopenharmony_ci#define HCIUARTSETPROTO		_IOW('U', 200, int)
178c2ecf20Sopenharmony_ci#define HCIUARTGETPROTO		_IOR('U', 201, int)
188c2ecf20Sopenharmony_ci#define HCIUARTGETDEVICE	_IOR('U', 202, int)
198c2ecf20Sopenharmony_ci#define HCIUARTSETFLAGS		_IOW('U', 203, int)
208c2ecf20Sopenharmony_ci#define HCIUARTGETFLAGS		_IOR('U', 204, int)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* UART protocols */
238c2ecf20Sopenharmony_ci#define HCI_UART_MAX_PROTO	12
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define HCI_UART_H4	0
268c2ecf20Sopenharmony_ci#define HCI_UART_BCSP	1
278c2ecf20Sopenharmony_ci#define HCI_UART_3WIRE	2
288c2ecf20Sopenharmony_ci#define HCI_UART_H4DS	3
298c2ecf20Sopenharmony_ci#define HCI_UART_LL	4
308c2ecf20Sopenharmony_ci#define HCI_UART_ATH3K	5
318c2ecf20Sopenharmony_ci#define HCI_UART_INTEL	6
328c2ecf20Sopenharmony_ci#define HCI_UART_BCM	7
338c2ecf20Sopenharmony_ci#define HCI_UART_QCA	8
348c2ecf20Sopenharmony_ci#define HCI_UART_AG6XX	9
358c2ecf20Sopenharmony_ci#define HCI_UART_NOKIA	10
368c2ecf20Sopenharmony_ci#define HCI_UART_MRVL	11
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define HCI_UART_RAW_DEVICE	0
398c2ecf20Sopenharmony_ci#define HCI_UART_RESET_ON_INIT	1
408c2ecf20Sopenharmony_ci#define HCI_UART_CREATE_AMP	2
418c2ecf20Sopenharmony_ci#define HCI_UART_INIT_PENDING	3
428c2ecf20Sopenharmony_ci#define HCI_UART_EXT_CONFIG	4
438c2ecf20Sopenharmony_ci#define HCI_UART_VND_DETECT	5
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistruct hci_uart;
468c2ecf20Sopenharmony_cistruct serdev_device;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistruct hci_uart_proto {
498c2ecf20Sopenharmony_ci	unsigned int id;
508c2ecf20Sopenharmony_ci	const char *name;
518c2ecf20Sopenharmony_ci	unsigned int manufacturer;
528c2ecf20Sopenharmony_ci	unsigned int init_speed;
538c2ecf20Sopenharmony_ci	unsigned int oper_speed;
548c2ecf20Sopenharmony_ci	int (*open)(struct hci_uart *hu);
558c2ecf20Sopenharmony_ci	int (*close)(struct hci_uart *hu);
568c2ecf20Sopenharmony_ci	int (*flush)(struct hci_uart *hu);
578c2ecf20Sopenharmony_ci	int (*setup)(struct hci_uart *hu);
588c2ecf20Sopenharmony_ci	int (*set_baudrate)(struct hci_uart *hu, unsigned int speed);
598c2ecf20Sopenharmony_ci	int (*recv)(struct hci_uart *hu, const void *data, int len);
608c2ecf20Sopenharmony_ci	int (*enqueue)(struct hci_uart *hu, struct sk_buff *skb);
618c2ecf20Sopenharmony_ci	struct sk_buff *(*dequeue)(struct hci_uart *hu);
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct hci_uart {
658c2ecf20Sopenharmony_ci	struct tty_struct	*tty;
668c2ecf20Sopenharmony_ci	struct serdev_device	*serdev;
678c2ecf20Sopenharmony_ci	struct hci_dev		*hdev;
688c2ecf20Sopenharmony_ci	unsigned long		flags;
698c2ecf20Sopenharmony_ci	unsigned long		hdev_flags;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	struct work_struct	init_ready;
728c2ecf20Sopenharmony_ci	struct work_struct	write_work;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	const struct hci_uart_proto *proto;
758c2ecf20Sopenharmony_ci	struct percpu_rw_semaphore proto_lock;	/* Stop work for proto close */
768c2ecf20Sopenharmony_ci	void			*priv;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	struct sk_buff		*tx_skb;
798c2ecf20Sopenharmony_ci	unsigned long		tx_state;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	unsigned int init_speed;
828c2ecf20Sopenharmony_ci	unsigned int oper_speed;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	u8			alignment;
858c2ecf20Sopenharmony_ci	u8			padding;
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* HCI_UART proto flag bits */
898c2ecf20Sopenharmony_ci#define HCI_UART_PROTO_SET	0
908c2ecf20Sopenharmony_ci#define HCI_UART_REGISTERED	1
918c2ecf20Sopenharmony_ci#define HCI_UART_PROTO_READY	2
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* TX states  */
948c2ecf20Sopenharmony_ci#define HCI_UART_SENDING	1
958c2ecf20Sopenharmony_ci#define HCI_UART_TX_WAKEUP	2
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciint hci_uart_register_proto(const struct hci_uart_proto *p);
988c2ecf20Sopenharmony_ciint hci_uart_unregister_proto(const struct hci_uart_proto *p);
998c2ecf20Sopenharmony_ciint hci_uart_register_device(struct hci_uart *hu, const struct hci_uart_proto *p);
1008c2ecf20Sopenharmony_civoid hci_uart_unregister_device(struct hci_uart *hu);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciint hci_uart_tx_wakeup(struct hci_uart *hu);
1038c2ecf20Sopenharmony_ciint hci_uart_wait_until_sent(struct hci_uart *hu);
1048c2ecf20Sopenharmony_ciint hci_uart_init_ready(struct hci_uart *hu);
1058c2ecf20Sopenharmony_civoid hci_uart_init_work(struct work_struct *work);
1068c2ecf20Sopenharmony_civoid hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed);
1078c2ecf20Sopenharmony_cibool hci_uart_has_flow_control(struct hci_uart *hu);
1088c2ecf20Sopenharmony_civoid hci_uart_set_flow_control(struct hci_uart *hu, bool enable);
1098c2ecf20Sopenharmony_civoid hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed,
1108c2ecf20Sopenharmony_ci			 unsigned int oper_speed);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_H4
1138c2ecf20Sopenharmony_ciint h4_init(void);
1148c2ecf20Sopenharmony_ciint h4_deinit(void);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistruct h4_recv_pkt {
1178c2ecf20Sopenharmony_ci	u8  type;	/* Packet type */
1188c2ecf20Sopenharmony_ci	u8  hlen;	/* Header length */
1198c2ecf20Sopenharmony_ci	u8  loff;	/* Data length offset in header */
1208c2ecf20Sopenharmony_ci	u8  lsize;	/* Data length field size */
1218c2ecf20Sopenharmony_ci	u16 maxlen;	/* Max overall packet length */
1228c2ecf20Sopenharmony_ci	int (*recv)(struct hci_dev *hdev, struct sk_buff *skb);
1238c2ecf20Sopenharmony_ci};
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#define H4_RECV_ACL \
1268c2ecf20Sopenharmony_ci	.type = HCI_ACLDATA_PKT, \
1278c2ecf20Sopenharmony_ci	.hlen = HCI_ACL_HDR_SIZE, \
1288c2ecf20Sopenharmony_ci	.loff = 2, \
1298c2ecf20Sopenharmony_ci	.lsize = 2, \
1308c2ecf20Sopenharmony_ci	.maxlen = HCI_MAX_FRAME_SIZE \
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci#define H4_RECV_SCO \
1338c2ecf20Sopenharmony_ci	.type = HCI_SCODATA_PKT, \
1348c2ecf20Sopenharmony_ci	.hlen = HCI_SCO_HDR_SIZE, \
1358c2ecf20Sopenharmony_ci	.loff = 2, \
1368c2ecf20Sopenharmony_ci	.lsize = 1, \
1378c2ecf20Sopenharmony_ci	.maxlen = HCI_MAX_SCO_SIZE
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#define H4_RECV_EVENT \
1408c2ecf20Sopenharmony_ci	.type = HCI_EVENT_PKT, \
1418c2ecf20Sopenharmony_ci	.hlen = HCI_EVENT_HDR_SIZE, \
1428c2ecf20Sopenharmony_ci	.loff = 1, \
1438c2ecf20Sopenharmony_ci	.lsize = 1, \
1448c2ecf20Sopenharmony_ci	.maxlen = HCI_MAX_EVENT_SIZE
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#define H4_RECV_ISO \
1478c2ecf20Sopenharmony_ci	.type = HCI_ISODATA_PKT, \
1488c2ecf20Sopenharmony_ci	.hlen = HCI_ISO_HDR_SIZE, \
1498c2ecf20Sopenharmony_ci	.loff = 2, \
1508c2ecf20Sopenharmony_ci	.lsize = 2, \
1518c2ecf20Sopenharmony_ci	.maxlen = HCI_MAX_FRAME_SIZE \
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cistruct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
1548c2ecf20Sopenharmony_ci			    const unsigned char *buffer, int count,
1558c2ecf20Sopenharmony_ci			    const struct h4_recv_pkt *pkts, int pkts_count);
1568c2ecf20Sopenharmony_ci#endif
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_BCSP
1598c2ecf20Sopenharmony_ciint bcsp_init(void);
1608c2ecf20Sopenharmony_ciint bcsp_deinit(void);
1618c2ecf20Sopenharmony_ci#endif
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_LL
1648c2ecf20Sopenharmony_ciint ll_init(void);
1658c2ecf20Sopenharmony_ciint ll_deinit(void);
1668c2ecf20Sopenharmony_ci#endif
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_ATH3K
1698c2ecf20Sopenharmony_ciint ath_init(void);
1708c2ecf20Sopenharmony_ciint ath_deinit(void);
1718c2ecf20Sopenharmony_ci#endif
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_3WIRE
1748c2ecf20Sopenharmony_ciint h5_init(void);
1758c2ecf20Sopenharmony_ciint h5_deinit(void);
1768c2ecf20Sopenharmony_ci#endif
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_INTEL
1798c2ecf20Sopenharmony_ciint intel_init(void);
1808c2ecf20Sopenharmony_ciint intel_deinit(void);
1818c2ecf20Sopenharmony_ci#endif
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_BCM
1848c2ecf20Sopenharmony_ciint bcm_init(void);
1858c2ecf20Sopenharmony_ciint bcm_deinit(void);
1868c2ecf20Sopenharmony_ci#endif
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_QCA
1898c2ecf20Sopenharmony_ciint qca_init(void);
1908c2ecf20Sopenharmony_ciint qca_deinit(void);
1918c2ecf20Sopenharmony_ci#endif
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_AG6XX
1948c2ecf20Sopenharmony_ciint ag6xx_init(void);
1958c2ecf20Sopenharmony_ciint ag6xx_deinit(void);
1968c2ecf20Sopenharmony_ci#endif
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ci#ifdef CONFIG_BT_HCIUART_MRVL
1998c2ecf20Sopenharmony_ciint mrvl_init(void);
2008c2ecf20Sopenharmony_ciint mrvl_deinit(void);
2018c2ecf20Sopenharmony_ci#endif
202