blob: 4e039d7a16f80de4a400e2bc784aa00f4583ed5c [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Marcel Holtmann0372a662005-10-28 19:20:45 +02003 *
4 * Bluetooth HCI UART driver
5 *
6 * Copyright (C) 2000-2001 Qualcomm Incorporated
7 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
8 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Marcel Holtmann0372a662005-10-28 19:20:45 +020011#ifndef N_HCI
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#define N_HCI 15
13#endif
14
15/* Ioctls */
Marcel Holtmannd2158742007-05-09 09:15:35 +020016#define HCIUARTSETPROTO _IOW('U', 200, int)
17#define HCIUARTGETPROTO _IOR('U', 201, int)
18#define HCIUARTGETDEVICE _IOR('U', 202, int)
Johan Hedberg63c7d092010-07-12 11:37:04 -030019#define HCIUARTSETFLAGS _IOW('U', 203, int)
20#define HCIUARTGETFLAGS _IOR('U', 204, int)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22/* UART protocols */
Loic Poulain162f8122016-09-19 16:29:27 +020023#define HCI_UART_MAX_PROTO 12
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25#define HCI_UART_H4 0
26#define HCI_UART_BCSP 1
27#define HCI_UART_3WIRE 2
28#define HCI_UART_H4DS 3
Ohad Ben-Cohen166d2f62007-10-20 13:42:36 +020029#define HCI_UART_LL 4
Suraj Sumangalab3190df2010-07-19 12:34:07 +053030#define HCI_UART_ATH3K 5
Marcel Holtmann16e38872015-04-04 16:13:02 -070031#define HCI_UART_INTEL 6
Marcel Holtmanne9a2dd22015-04-04 16:13:03 -070032#define HCI_UART_BCM 7
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -070033#define HCI_UART_QCA 8
Loic Poulain395174b2016-02-22 10:48:03 +010034#define HCI_UART_AG6XX 9
Loic Poulain9e691302016-09-19 11:32:35 +020035#define HCI_UART_NOKIA 10
Loic Poulain162f8122016-09-19 16:29:27 +020036#define HCI_UART_MRVL 11
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Johan Hedberg63c7d092010-07-12 11:37:04 -030038#define HCI_UART_RAW_DEVICE 0
Marcel Holtmanna55e1f32012-02-24 17:12:24 +010039#define HCI_UART_RESET_ON_INIT 1
Marcel Holtmann8a7a3fd62012-02-24 17:09:38 +010040#define HCI_UART_CREATE_AMP 2
Johan Hedberg9f2aee82012-07-16 16:12:11 +030041#define HCI_UART_INIT_PENDING 3
Marcel Holtmann6afd04a2014-07-11 07:12:58 +020042#define HCI_UART_EXT_CONFIG 4
Marcel Holtmannfb2ce8d2015-04-04 16:13:01 -070043#define HCI_UART_VND_DETECT 5
Johan Hedberg63c7d092010-07-12 11:37:04 -030044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045struct hci_uart;
Rob Herring82f51692017-03-28 17:59:35 +020046struct serdev_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48struct hci_uart_proto {
49 unsigned int id;
Marcel Holtmann7c40fb82015-04-04 22:27:34 -070050 const char *name;
Marcel Holtmannaee61f72015-10-20 21:30:45 +020051 unsigned int manufacturer;
Frederic Danis77213832015-05-28 11:25:03 +020052 unsigned int init_speed;
53 unsigned int oper_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 int (*open)(struct hci_uart *hu);
55 int (*close)(struct hci_uart *hu);
56 int (*flush)(struct hci_uart *hu);
Marcel Holtmann6ae4fdd2015-04-05 22:52:17 -070057 int (*setup)(struct hci_uart *hu);
Frederic Danis77213832015-05-28 11:25:03 +020058 int (*set_baudrate)(struct hci_uart *hu, unsigned int speed);
Marcel Holtmann9d1c40e2015-04-04 20:59:41 -070059 int (*recv)(struct hci_uart *hu, const void *data, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 int (*enqueue)(struct hci_uart *hu, struct sk_buff *skb);
61 struct sk_buff *(*dequeue)(struct hci_uart *hu);
62};
63
64struct hci_uart {
Marcel Holtmann0372a662005-10-28 19:20:45 +020065 struct tty_struct *tty;
Rob Herring82f51692017-03-28 17:59:35 +020066 struct serdev_device *serdev;
Marcel Holtmann0372a662005-10-28 19:20:45 +020067 struct hci_dev *hdev;
68 unsigned long flags;
Johan Hedberg63c7d092010-07-12 11:37:04 -030069 unsigned long hdev_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Johan Hedberg9f2aee82012-07-16 16:12:11 +030071 struct work_struct init_ready;
Felipe Balbida64c272014-04-23 09:58:26 -050072 struct work_struct write_work;
Johan Hedberg9f2aee82012-07-16 16:12:11 +030073
Marcel Holtmann4ee7ef12015-04-04 22:11:43 -070074 const struct hci_uart_proto *proto;
Ronald Tschalär67d2f872017-10-25 22:14:53 -070075 struct percpu_rw_semaphore proto_lock; /* Stop work for proto close */
Marcel Holtmann0372a662005-10-28 19:20:45 +020076 void *priv;
77
78 struct sk_buff *tx_skb;
79 unsigned long tx_state;
Ilya Faenson2a973df2015-06-17 17:30:56 -040080
81 unsigned int init_speed;
82 unsigned int oper_speed;
Sebastian Reichelaeac3012017-03-28 17:59:34 +020083
84 u8 alignment;
85 u8 padding;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
Johan Hedberg63c7d092010-07-12 11:37:04 -030088/* HCI_UART proto flag bits */
Marcel Holtmann0372a662005-10-28 19:20:45 +020089#define HCI_UART_PROTO_SET 0
Johan Hedberg9f2aee82012-07-16 16:12:11 +030090#define HCI_UART_REGISTERED 1
Loic Poulain84cb3df2016-04-04 10:48:13 +020091#define HCI_UART_PROTO_READY 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93/* TX states */
Marcel Holtmann0372a662005-10-28 19:20:45 +020094#define HCI_UART_SENDING 1
95#define HCI_UART_TX_WAKEUP 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Marcel Holtmann4ee7ef12015-04-04 22:11:43 -070097int hci_uart_register_proto(const struct hci_uart_proto *p);
98int hci_uart_unregister_proto(const struct hci_uart_proto *p);
Rob Herring82f51692017-03-28 17:59:35 +020099int hci_uart_register_device(struct hci_uart *hu, const struct hci_uart_proto *p);
Ian Moltonc34dc3b2017-07-08 17:37:41 +0100100void hci_uart_unregister_device(struct hci_uart *hu);
Rob Herring82f51692017-03-28 17:59:35 +0200101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102int hci_uart_tx_wakeup(struct hci_uart *hu);
Sascha Hauer40fbb912019-06-14 09:23:49 +0200103int hci_uart_wait_until_sent(struct hci_uart *hu);
Johan Hedberg9f2aee82012-07-16 16:12:11 +0300104int hci_uart_init_ready(struct hci_uart *hu);
Hans de Goedefdee6d82018-05-27 21:04:53 +0200105void hci_uart_init_work(struct work_struct *work);
Frederic Danis77213832015-05-28 11:25:03 +0200106void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed);
Vladis Dronovb36a1552019-07-30 11:33:45 +0200107bool hci_uart_has_flow_control(struct hci_uart *hu);
Ilya Faenson2a973df2015-06-17 17:30:56 -0400108void hci_uart_set_flow_control(struct hci_uart *hu, bool enable);
109void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed,
110 unsigned int oper_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Marcel Holtmann0372a662005-10-28 19:20:45 +0200112#ifdef CONFIG_BT_HCIUART_H4
113int h4_init(void);
114int h4_deinit(void);
Marcel Holtmanne1a38d72015-04-04 21:59:24 -0700115
Marcel Holtmann79b8df92015-04-05 23:44:59 -0700116struct h4_recv_pkt {
117 u8 type; /* Packet type */
118 u8 hlen; /* Header length */
119 u8 loff; /* Data length offset in header */
120 u8 lsize; /* Data length field size */
121 u16 maxlen; /* Max overall packet length */
122 int (*recv)(struct hci_dev *hdev, struct sk_buff *skb);
123};
124
125#define H4_RECV_ACL \
126 .type = HCI_ACLDATA_PKT, \
127 .hlen = HCI_ACL_HDR_SIZE, \
128 .loff = 2, \
129 .lsize = 2, \
130 .maxlen = HCI_MAX_FRAME_SIZE \
131
132#define H4_RECV_SCO \
133 .type = HCI_SCODATA_PKT, \
134 .hlen = HCI_SCO_HDR_SIZE, \
135 .loff = 2, \
136 .lsize = 1, \
137 .maxlen = HCI_MAX_SCO_SIZE
138
139#define H4_RECV_EVENT \
140 .type = HCI_EVENT_PKT, \
141 .hlen = HCI_EVENT_HDR_SIZE, \
142 .loff = 1, \
143 .lsize = 1, \
144 .maxlen = HCI_MAX_EVENT_SIZE
145
Luiz Augusto von Dentzef564112020-01-15 13:02:19 -0800146#define H4_RECV_ISO \
147 .type = HCI_ISODATA_PKT, \
148 .hlen = HCI_ISO_HDR_SIZE, \
149 .loff = 2, \
150 .lsize = 2, \
151 .maxlen = HCI_MAX_FRAME_SIZE \
152
Marcel Holtmanne1a38d72015-04-04 21:59:24 -0700153struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
Marcel Holtmann79b8df92015-04-05 23:44:59 -0700154 const unsigned char *buffer, int count,
155 const struct h4_recv_pkt *pkts, int pkts_count);
Marcel Holtmann0372a662005-10-28 19:20:45 +0200156#endif
157
158#ifdef CONFIG_BT_HCIUART_BCSP
159int bcsp_init(void);
160int bcsp_deinit(void);
161#endif
Ohad Ben-Cohen166d2f62007-10-20 13:42:36 +0200162
163#ifdef CONFIG_BT_HCIUART_LL
164int ll_init(void);
165int ll_deinit(void);
166#endif
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530167
168#ifdef CONFIG_BT_HCIUART_ATH3K
169int ath_init(void);
170int ath_deinit(void);
171#endif
Johan Hedberg7dec65c2012-07-16 16:12:02 +0300172
173#ifdef CONFIG_BT_HCIUART_3WIRE
174int h5_init(void);
175int h5_deinit(void);
176#endif
Marcel Holtmann16e38872015-04-04 16:13:02 -0700177
Loic Poulainca93cee2015-07-01 12:20:26 +0200178#ifdef CONFIG_BT_HCIUART_INTEL
179int intel_init(void);
180int intel_deinit(void);
181#endif
182
Marcel Holtmannbdd88182015-04-05 22:52:18 -0700183#ifdef CONFIG_BT_HCIUART_BCM
184int bcm_init(void);
185int bcm_deinit(void);
186#endif
Ben Young Tae Kim0ff252c2015-08-10 14:24:17 -0700187
188#ifdef CONFIG_BT_HCIUART_QCA
189int qca_init(void);
190int qca_deinit(void);
191#endif
Loic Poulain395174b2016-02-22 10:48:03 +0100192
193#ifdef CONFIG_BT_HCIUART_AG6XX
194int ag6xx_init(void);
195int ag6xx_deinit(void);
196#endif
Loic Poulain162f8122016-09-19 16:29:27 +0200197
198#ifdef CONFIG_BT_HCIUART_MRVL
199int mrvl_init(void);
200int mrvl_deinit(void);
201#endif