1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * Bluetooth support for Intel PCIe devices
6 * Copyright (C) 2024 Intel Corporation
9 /* Control and Status Register(BTINTEL_PCIE_CSR) */
10 #define BTINTEL_PCIE_CSR_BASE (0x000)
11 #define BTINTEL_PCIE_CSR_FUNC_CTRL_REG (BTINTEL_PCIE_CSR_BASE + 0x024)
12 #define BTINTEL_PCIE_CSR_HW_REV_REG (BTINTEL_PCIE_CSR_BASE + 0x028)
13 #define BTINTEL_PCIE_CSR_RF_ID_REG (BTINTEL_PCIE_CSR_BASE + 0x09C)
14 #define BTINTEL_PCIE_CSR_BOOT_STAGE_REG (BTINTEL_PCIE_CSR_BASE + 0x108)
15 #define BTINTEL_PCIE_CSR_IPC_SLEEP_CTL_REG (BTINTEL_PCIE_CSR_BASE + 0x114)
16 #define BTINTEL_PCIE_CSR_CI_ADDR_LSB_REG (BTINTEL_PCIE_CSR_BASE + 0x118)
17 #define BTINTEL_PCIE_CSR_CI_ADDR_MSB_REG (BTINTEL_PCIE_CSR_BASE + 0x11C)
18 #define BTINTEL_PCIE_CSR_IMG_RESPONSE_REG (BTINTEL_PCIE_CSR_BASE + 0x12C)
19 #define BTINTEL_PCIE_CSR_HBUS_TARG_WRPTR (BTINTEL_PCIE_CSR_BASE + 0x460)
21 /* BTINTEL_PCIE_CSR Function Control Register */
22 #define BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_ENA (BIT(0))
23 #define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_INIT (BIT(6))
24 #define BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_INIT (BIT(7))
25 #define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_STS (BIT(20))
26 #define BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_STS (BIT(28))
27 #define BTINTEL_PCIE_CSR_FUNC_CTRL_BUS_MASTER_DISCON (BIT(29))
28 #define BTINTEL_PCIE_CSR_FUNC_CTRL_SW_RESET (BIT(31))
30 /* Value for BTINTEL_PCIE_CSR_BOOT_STAGE register */
31 #define BTINTEL_PCIE_CSR_BOOT_STAGE_ROM (BIT(0))
32 #define BTINTEL_PCIE_CSR_BOOT_STAGE_IML (BIT(1))
33 #define BTINTEL_PCIE_CSR_BOOT_STAGE_OPFW (BIT(2))
34 #define BTINTEL_PCIE_CSR_BOOT_STAGE_ROM_LOCKDOWN (BIT(10))
35 #define BTINTEL_PCIE_CSR_BOOT_STAGE_IML_LOCKDOWN (BIT(11))
36 #define BTINTEL_PCIE_CSR_BOOT_STAGE_MAC_ACCESS_ON (BIT(16))
37 #define BTINTEL_PCIE_CSR_BOOT_STAGE_ALIVE (BIT(23))
38 #define BTINTEL_PCIE_CSR_BOOT_STAGE_D3_STATE_READY (BIT(24))
40 /* Registers for MSI-X */
41 #define BTINTEL_PCIE_CSR_MSIX_BASE (0x2000)
42 #define BTINTEL_PCIE_CSR_MSIX_FH_INT_CAUSES (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0800)
43 #define BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0804)
44 #define BTINTEL_PCIE_CSR_MSIX_HW_INT_CAUSES (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0808)
45 #define BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK (BTINTEL_PCIE_CSR_MSIX_BASE + 0x080C)
46 #define BTINTEL_PCIE_CSR_MSIX_AUTOMASK_ST (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0810)
47 #define BTINTEL_PCIE_CSR_MSIX_AUTOMASK_EN (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0814)
48 #define BTINTEL_PCIE_CSR_MSIX_IVAR_BASE (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0880)
49 #define BTINTEL_PCIE_CSR_MSIX_IVAR(cause) (BTINTEL_PCIE_CSR_MSIX_IVAR_BASE + (cause))
51 /* Causes for the FH register interrupts */
52 enum msix_fh_int_causes
{
53 BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0
= BIT(0), /* cause 0 */
54 BTINTEL_PCIE_MSIX_FH_INT_CAUSES_1
= BIT(1), /* cause 1 */
57 /* Causes for the HW register interrupts */
58 enum msix_hw_int_causes
{
59 BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0
= BIT(0), /* cause 32 */
63 * Host-Device interface is active
64 * Host-Device interface is inactive(as reflected by IPC_SLEEP_CONTROL_CSR_AD)
65 * Host-Device interface is inactive(as reflected by IPC_SLEEP_CONTROL_CSR_AD)
68 BTINTEL_PCIE_STATE_D0
= 0,
69 BTINTEL_PCIE_STATE_D3_HOT
= 2,
70 BTINTEL_PCIE_STATE_D3_COLD
= 3,
72 #define BTINTEL_PCIE_MSIX_NON_AUTO_CLEAR_CAUSE BIT(7)
74 /* Minimum and Maximum number of MSI-X Vector
75 * Intel Bluetooth PCIe support only 1 vector
77 #define BTINTEL_PCIE_MSIX_VEC_MAX 1
78 #define BTINTEL_PCIE_MSIX_VEC_MIN 1
80 /* Default poll time for MAC access during init */
81 #define BTINTEL_DEFAULT_MAC_ACCESS_TIMEOUT_US 200000
83 /* Default interrupt timeout in msec */
84 #define BTINTEL_DEFAULT_INTR_TIMEOUT_MS 3000
86 /* The number of descriptors in TX/RX queues */
87 #define BTINTEL_DESCS_COUNT 16
89 /* Number of Queue for TX and RX
90 * It indicates the index of the IA(Index Array)
93 BTINTEL_PCIE_TXQ_NUM
= 0,
94 BTINTEL_PCIE_RXQ_NUM
= 1,
95 BTINTEL_PCIE_NUM_QUEUES
= 2,
98 /* The size of DMA buffer for TX and RX in bytes */
99 #define BTINTEL_PCIE_BUFFER_SIZE 4096
101 /* DMA allocation alignment */
102 #define BTINTEL_PCIE_DMA_POOL_ALIGNMENT 256
104 #define BTINTEL_PCIE_TX_WAIT_TIMEOUT_MS 500
106 /* Doorbell vector for TFD */
107 #define BTINTEL_PCIE_TX_DB_VEC 0
109 /* Number of pending RX requests for downlink */
110 #define BTINTEL_PCIE_RX_MAX_QUEUE 6
112 /* Doorbell vector for FRBD */
113 #define BTINTEL_PCIE_RX_DB_VEC 513
115 /* RBD buffer size mapping */
116 #define BTINTEL_PCIE_RBD_SIZE_4K 0x04
119 * Struct for Context Information (v2)
121 * All members are write-only for host and read-only for device.
123 * @version: Version of context information
124 * @size: Size of context information
125 * @config: Config with which host wants peripheral to execute
126 * Subset of capability register published by device
127 * @addr_tr_hia: Address of TR Head Index Array
128 * @addr_tr_tia: Address of TR Tail Index Array
129 * @addr_cr_hia: Address of CR Head Index Array
130 * @addr_cr_tia: Address of CR Tail Index Array
131 * @num_tr_ia: Number of entries in TR Index Arrays
132 * @num_cr_ia: Number of entries in CR Index Arrays
133 * @rbd_siz: RBD Size { 0x4=4K }
134 * @addr_tfdq: Address of TFD Queue(tx)
135 * @addr_urbdq0: Address of URBD Queue(tx)
136 * @num_tfdq: Number of TFD in TFD Queue(tx)
137 * @num_urbdq0: Number of URBD in URBD Queue(tx)
138 * @tfdq_db_vec: Queue number of TFD
139 * @urbdq0_db_vec: Queue number of URBD
140 * @addr_frbdq: Address of FRBD Queue(rx)
141 * @addr_urbdq1: Address of URBD Queue(rx)
142 * @num_frbdq: Number of FRBD in FRBD Queue(rx)
143 * @frbdq_db_vec: Queue number of FRBD
144 * @num_urbdq1: Number of URBD in URBD Queue(rx)
145 * @urbdq_db_vec: Queue number of URBDQ1
146 * @tr_msi_vec: Transfer Ring MSI-X Vector
147 * @cr_msi_vec: Completion Ring MSI-X Vector
148 * @dbgc_addr: DBGC first fragment address
149 * @dbgc_size: DBGC buffer size
150 * @early_enable: Enarly debug enable
151 * @dbg_output_mode: Debug output mode
152 * Bit[4] DBGC O/P { 0=SRAM, 1=DRAM(not relevant for NPK) }
153 * Bit[5] DBGC I/P { 0=BDBG, 1=DBGI }
154 * Bits[6:7] DBGI O/P(relevant if bit[5] = 1)
155 * 0=BT DBGC, 1=WiFi DBGC, 2=NPK }
156 * @dbg_preset: Debug preset
157 * @ext_addr: Address of context information extension
158 * @ext_size: Size of context information part
205 /* Transfer Descriptor for TX
206 * @type: Not in use. Set to 0x0
207 * @size: Size of data in the buffer
208 * @addr: DMA Address of buffer
218 /* URB Descriptor for TX
219 * @tfd_index: Index of TFD in TFDQ + 1
220 * @num_txq: Queue index of TFD Queue
221 * @cmpl_count: Completion count. Always 0x01
222 * @immediate_cmpl: Immediate completion flag: Always 0x01
232 /* FRB Descriptor for RX
233 * @tag: RX buffer tag (index of RX buffer queue)
234 * @addr: Address of buffer
243 /* URB Descriptor for RX
244 * @frbd_tag: Tag from FRBD
254 /* RFH header in RX packet
255 * @packet_len: Length of the data in the buffer
256 * @rxq: RX Queue number
257 * @cmd_id: Command ID. Not in Use
267 /* Internal data buffer
268 * @data: pointer to the data buffer
269 * @p_addr: physical address of data buffer
273 dma_addr_t data_p_addr
;
278 dma_addr_t tr_hia_p_addr
;
280 dma_addr_t tr_tia_p_addr
;
282 dma_addr_t cr_hia_p_addr
;
284 dma_addr_t cr_tia_p_addr
;
288 /* Structure for TX Queue
289 * @count: Number of descriptors
290 * @tfds: Array of TFD
291 * @urbd0s: Array of URBD0
292 * @buf: Array of data_buf structure
297 dma_addr_t tfds_p_addr
;
300 dma_addr_t urbd0s_p_addr
;
301 struct urbd0
*urbd0s
;
303 dma_addr_t buf_p_addr
;
305 struct data_buf
*bufs
;
308 /* Structure for RX Queue
309 * @count: Number of descriptors
310 * @frbds: Array of FRBD
311 * @urbd1s: Array of URBD1
312 * @buf: Array of data_buf structure
317 dma_addr_t frbds_p_addr
;
320 dma_addr_t urbd1s_p_addr
;
321 struct urbd1
*urbd1s
;
323 dma_addr_t buf_p_addr
;
325 struct data_buf
*bufs
;
328 /* struct btintel_pcie_data
331 * @flags: driver state
332 * @irq_lock: spinlock for MSI-X
333 * @hci_rx_lock: spinlock for HCI RX flow
334 * @base_addr: pci base address (from BAR)
335 * @msix_entries: array of MSI-X entries
336 * @msix_enabled: true if MSI-X is enabled;
337 * @alloc_vecs: number of interrupt vectors allocated
338 * @def_irq: default irq for all causes
339 * @fh_init_mask: initial unmasked rxq causes
340 * @hw_init_mask: initial unmaksed hw causes
341 * @boot_stage_cache: cached value of boot stage register
342 * @img_resp_cache: cached value of image response register
343 * @cnvi: CNVi register value
344 * @cnvr: CNVr register value
345 * @gp0_received: condition for gp0 interrupt
346 * @gp0_wait_q: wait_q for gp0 interrupt
347 * @tx_wait_done: condition for tx interrupt
348 * @tx_wait_q: wait_q for tx interrupt
349 * @workqueue: workqueue for RX work
350 * @rx_skb_q: SKB queue for RX packet
351 * @rx_work: RX work struct to process the RX packet in @rx_skb_q
352 * @dma_pool: DMA pool for descriptors, index array and ci
353 * @dma_p_addr: DMA address for pool
354 * @dma_v_addr: address of pool
355 * @ci_p_addr: DMA address for CI struct
357 * @ia: Index Array struct
358 * @txq: TX Queue struct
359 * @rxq: RX Queue struct
360 * @alive_intr_ctxt: Alive interrupt context
362 struct btintel_pcie_data
{
363 struct pci_dev
*pdev
;
364 struct hci_dev
*hdev
;
367 /* lock used in MSI-X interrupt */
369 /* lock to serialize rx events */
370 spinlock_t hci_rx_lock
;
372 void __iomem
*base_addr
;
374 struct msix_entry msix_entries
[BTINTEL_PCIE_MSIX_VEC_MAX
];
382 u32 boot_stage_cache
;
389 wait_queue_head_t gp0_wait_q
;
392 wait_queue_head_t tx_wait_q
;
394 struct workqueue_struct
*workqueue
;
395 struct sk_buff_head rx_skb_q
;
396 struct work_struct rx_work
;
398 struct dma_pool
*dma_pool
;
399 dma_addr_t dma_p_addr
;
402 dma_addr_t ci_p_addr
;
410 static inline u32
btintel_pcie_rd_reg32(struct btintel_pcie_data
*data
,
413 return ioread32(data
->base_addr
+ offset
);
416 static inline void btintel_pcie_wr_reg8(struct btintel_pcie_data
*data
,
419 iowrite8(val
, data
->base_addr
+ offset
);
422 static inline void btintel_pcie_wr_reg32(struct btintel_pcie_data
*data
,
425 iowrite32(val
, data
->base_addr
+ offset
);
428 static inline void btintel_pcie_set_reg_bits(struct btintel_pcie_data
*data
,
429 u32 offset
, u32 bits
)
433 r
= ioread32(data
->base_addr
+ offset
);
435 iowrite32(r
, data
->base_addr
+ offset
);
438 static inline void btintel_pcie_clr_reg_bits(struct btintel_pcie_data
*data
,
439 u32 offset
, u32 bits
)
443 r
= ioread32(data
->base_addr
+ offset
);
445 iowrite32(r
, data
->base_addr
+ offset
);