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_CI_ADDR_LSB_REG (BTINTEL_PCIE_CSR_BASE + 0x118)
16 #define BTINTEL_PCIE_CSR_CI_ADDR_MSB_REG (BTINTEL_PCIE_CSR_BASE + 0x11C)
17 #define BTINTEL_PCIE_CSR_IMG_RESPONSE_REG (BTINTEL_PCIE_CSR_BASE + 0x12C)
18 #define BTINTEL_PCIE_CSR_HBUS_TARG_WRPTR (BTINTEL_PCIE_CSR_BASE + 0x460)
20 /* BTINTEL_PCIE_CSR Function Control Register */
21 #define BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_ENA (BIT(0))
22 #define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_INIT (BIT(6))
23 #define BTINTEL_PCIE_CSR_FUNC_CTRL_FUNC_INIT (BIT(7))
24 #define BTINTEL_PCIE_CSR_FUNC_CTRL_MAC_ACCESS_STS (BIT(20))
25 #define BTINTEL_PCIE_CSR_FUNC_CTRL_SW_RESET (BIT(31))
27 /* Value for BTINTEL_PCIE_CSR_BOOT_STAGE register */
28 #define BTINTEL_PCIE_CSR_BOOT_STAGE_ROM (BIT(0))
29 #define BTINTEL_PCIE_CSR_BOOT_STAGE_IML (BIT(1))
30 #define BTINTEL_PCIE_CSR_BOOT_STAGE_OPFW (BIT(2))
31 #define BTINTEL_PCIE_CSR_BOOT_STAGE_ROM_LOCKDOWN (BIT(10))
32 #define BTINTEL_PCIE_CSR_BOOT_STAGE_IML_LOCKDOWN (BIT(11))
33 #define BTINTEL_PCIE_CSR_BOOT_STAGE_MAC_ACCESS_ON (BIT(16))
34 #define BTINTEL_PCIE_CSR_BOOT_STAGE_ALIVE (BIT(23))
36 /* Registers for MSI-X */
37 #define BTINTEL_PCIE_CSR_MSIX_BASE (0x2000)
38 #define BTINTEL_PCIE_CSR_MSIX_FH_INT_CAUSES (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0800)
39 #define BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0804)
40 #define BTINTEL_PCIE_CSR_MSIX_HW_INT_CAUSES (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0808)
41 #define BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK (BTINTEL_PCIE_CSR_MSIX_BASE + 0x080C)
42 #define BTINTEL_PCIE_CSR_MSIX_AUTOMASK_ST (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0810)
43 #define BTINTEL_PCIE_CSR_MSIX_AUTOMASK_EN (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0814)
44 #define BTINTEL_PCIE_CSR_MSIX_IVAR_BASE (BTINTEL_PCIE_CSR_MSIX_BASE + 0x0880)
45 #define BTINTEL_PCIE_CSR_MSIX_IVAR(cause) (BTINTEL_PCIE_CSR_MSIX_IVAR_BASE + (cause))
47 /* Causes for the FH register interrupts */
48 enum msix_fh_int_causes {
49 BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0 = BIT(0), /* cause 0 */
50 BTINTEL_PCIE_MSIX_FH_INT_CAUSES_1 = BIT(1), /* cause 1 */
53 /* Causes for the HW register interrupts */
54 enum msix_hw_int_causes {
55 BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0 = BIT(0), /* cause 32 */
58 #define BTINTEL_PCIE_MSIX_NON_AUTO_CLEAR_CAUSE BIT(7)
60 /* Minimum and Maximum number of MSI-X Vector
61 * Intel Bluetooth PCIe support only 1 vector
63 #define BTINTEL_PCIE_MSIX_VEC_MAX 1
64 #define BTINTEL_PCIE_MSIX_VEC_MIN 1
66 /* Default poll time for MAC access during init */
67 #define BTINTEL_DEFAULT_MAC_ACCESS_TIMEOUT_US 200000
69 /* Default interrupt timeout in msec */
70 #define BTINTEL_DEFAULT_INTR_TIMEOUT 3000
72 /* The number of descriptors in TX/RX queues */
73 #define BTINTEL_DESCS_COUNT 16
75 /* Number of Queue for TX and RX
76 * It indicates the index of the IA(Index Array)
79 BTINTEL_PCIE_TXQ_NUM = 0,
80 BTINTEL_PCIE_RXQ_NUM = 1,
81 BTINTEL_PCIE_NUM_QUEUES = 2,
84 /* The size of DMA buffer for TX and RX in bytes */
85 #define BTINTEL_PCIE_BUFFER_SIZE 4096
87 /* DMA allocation alignment */
88 #define BTINTEL_PCIE_DMA_POOL_ALIGNMENT 256
90 #define BTINTEL_PCIE_TX_WAIT_TIMEOUT_MS 500
92 /* Doorbell vector for TFD */
93 #define BTINTEL_PCIE_TX_DB_VEC 0
95 /* Number of pending RX requests for downlink */
96 #define BTINTEL_PCIE_RX_MAX_QUEUE 6
98 /* Doorbell vector for FRBD */
99 #define BTINTEL_PCIE_RX_DB_VEC 513
101 /* RBD buffer size mapping */
102 #define BTINTEL_PCIE_RBD_SIZE_4K 0x04
105 * Struct for Context Information (v2)
107 * All members are write-only for host and read-only for device.
109 * @version: Version of context information
110 * @size: Size of context information
111 * @config: Config with which host wants peripheral to execute
112 * Subset of capability register published by device
113 * @addr_tr_hia: Address of TR Head Index Array
114 * @addr_tr_tia: Address of TR Tail Index Array
115 * @addr_cr_hia: Address of CR Head Index Array
116 * @addr_cr_tia: Address of CR Tail Index Array
117 * @num_tr_ia: Number of entries in TR Index Arrays
118 * @num_cr_ia: Number of entries in CR Index Arrays
119 * @rbd_siz: RBD Size { 0x4=4K }
120 * @addr_tfdq: Address of TFD Queue(tx)
121 * @addr_urbdq0: Address of URBD Queue(tx)
122 * @num_tfdq: Number of TFD in TFD Queue(tx)
123 * @num_urbdq0: Number of URBD in URBD Queue(tx)
124 * @tfdq_db_vec: Queue number of TFD
125 * @urbdq0_db_vec: Queue number of URBD
126 * @addr_frbdq: Address of FRBD Queue(rx)
127 * @addr_urbdq1: Address of URBD Queue(rx)
128 * @num_frbdq: Number of FRBD in FRBD Queue(rx)
129 * @frbdq_db_vec: Queue number of FRBD
130 * @num_urbdq1: Number of URBD in URBD Queue(rx)
131 * @urbdq_db_vec: Queue number of URBDQ1
132 * @tr_msi_vec: Transfer Ring MSI-X Vector
133 * @cr_msi_vec: Completion Ring MSI-X Vector
134 * @dbgc_addr: DBGC first fragment address
135 * @dbgc_size: DBGC buffer size
136 * @early_enable: Enarly debug enable
137 * @dbg_output_mode: Debug output mode
138 * Bit[4] DBGC O/P { 0=SRAM, 1=DRAM(not relevant for NPK) }
139 * Bit[5] DBGC I/P { 0=BDBG, 1=DBGI }
140 * Bits[6:7] DBGI O/P(relevant if bit[5] = 1)
141 * 0=BT DBGC, 1=WiFi DBGC, 2=NPK }
142 * @dbg_preset: Debug preset
143 * @ext_addr: Address of context information extension
144 * @ext_size: Size of context information part
191 /* Transfer Descriptor for TX
192 * @type: Not in use. Set to 0x0
193 * @size: Size of data in the buffer
194 * @addr: DMA Address of buffer
204 /* URB Descriptor for TX
205 * @tfd_index: Index of TFD in TFDQ + 1
206 * @num_txq: Queue index of TFD Queue
207 * @cmpl_count: Completion count. Always 0x01
208 * @immediate_cmpl: Immediate completion flag: Always 0x01
218 /* FRB Descriptor for RX
219 * @tag: RX buffer tag (index of RX buffer queue)
220 * @addr: Address of buffer
229 /* URB Descriptor for RX
230 * @frbd_tag: Tag from FRBD
240 /* RFH header in RX packet
241 * @packet_len: Length of the data in the buffer
242 * @rxq: RX Queue number
243 * @cmd_id: Command ID. Not in Use
253 /* Internal data buffer
254 * @data: pointer to the data buffer
255 * @p_addr: physical address of data buffer
259 dma_addr_t data_p_addr;
264 dma_addr_t tr_hia_p_addr;
266 dma_addr_t tr_tia_p_addr;
268 dma_addr_t cr_hia_p_addr;
270 dma_addr_t cr_tia_p_addr;
274 /* Structure for TX Queue
275 * @count: Number of descriptors
276 * @tfds: Array of TFD
277 * @urbd0s: Array of URBD0
278 * @buf: Array of data_buf structure
283 dma_addr_t tfds_p_addr;
286 dma_addr_t urbd0s_p_addr;
287 struct urbd0 *urbd0s;
289 dma_addr_t buf_p_addr;
291 struct data_buf *bufs;
294 /* Structure for RX Queue
295 * @count: Number of descriptors
296 * @frbds: Array of FRBD
297 * @urbd1s: Array of URBD1
298 * @buf: Array of data_buf structure
303 dma_addr_t frbds_p_addr;
306 dma_addr_t urbd1s_p_addr;
307 struct urbd1 *urbd1s;
309 dma_addr_t buf_p_addr;
311 struct data_buf *bufs;
314 /* struct btintel_pcie_data
317 * @flags: driver state
318 * @irq_lock: spinlock for MSI-X
319 * @hci_rx_lock: spinlock for HCI RX flow
320 * @base_addr: pci base address (from BAR)
321 * @msix_entries: array of MSI-X entries
322 * @msix_enabled: true if MSI-X is enabled;
323 * @alloc_vecs: number of interrupt vectors allocated
324 * @def_irq: default irq for all causes
325 * @fh_init_mask: initial unmasked rxq causes
326 * @hw_init_mask: initial unmaksed hw causes
327 * @boot_stage_cache: cached value of boot stage register
328 * @img_resp_cache: cached value of image response register
329 * @cnvi: CNVi register value
330 * @cnvr: CNVr register value
331 * @gp0_received: condition for gp0 interrupt
332 * @gp0_wait_q: wait_q for gp0 interrupt
333 * @tx_wait_done: condition for tx interrupt
334 * @tx_wait_q: wait_q for tx interrupt
335 * @workqueue: workqueue for RX work
336 * @rx_skb_q: SKB queue for RX packet
337 * @rx_work: RX work struct to process the RX packet in @rx_skb_q
338 * @dma_pool: DMA pool for descriptors, index array and ci
339 * @dma_p_addr: DMA address for pool
340 * @dma_v_addr: address of pool
341 * @ci_p_addr: DMA address for CI struct
343 * @ia: Index Array struct
344 * @txq: TX Queue struct
345 * @rxq: RX Queue struct
347 struct btintel_pcie_data {
348 struct pci_dev *pdev;
349 struct hci_dev *hdev;
352 /* lock used in MSI-X interrupt */
354 /* lock to serialize rx events */
355 spinlock_t hci_rx_lock;
357 void __iomem *base_addr;
359 struct msix_entry msix_entries[BTINTEL_PCIE_MSIX_VEC_MAX];
367 u32 boot_stage_cache;
374 wait_queue_head_t gp0_wait_q;
377 wait_queue_head_t tx_wait_q;
379 struct workqueue_struct *workqueue;
380 struct sk_buff_head rx_skb_q;
381 struct work_struct rx_work;
383 struct dma_pool *dma_pool;
384 dma_addr_t dma_p_addr;
387 dma_addr_t ci_p_addr;
394 static inline u32 btintel_pcie_rd_reg32(struct btintel_pcie_data *data,
397 return ioread32(data->base_addr + offset);
400 static inline void btintel_pcie_wr_reg8(struct btintel_pcie_data *data,
403 iowrite8(val, data->base_addr + offset);
406 static inline void btintel_pcie_wr_reg32(struct btintel_pcie_data *data,
409 iowrite32(val, data->base_addr + offset);
412 static inline void btintel_pcie_set_reg_bits(struct btintel_pcie_data *data,
413 u32 offset, u32 bits)
417 r = ioread32(data->base_addr + offset);
419 iowrite32(r, data->base_addr + offset);
422 static inline void btintel_pcie_clr_reg_bits(struct btintel_pcie_data *data,
423 u32 offset, u32 bits)
427 r = ioread32(data->base_addr + offset);
429 iowrite32(r, data->base_addr + offset);