xref: /freebsd/sys/dev/qat/qat_common/adf_gen2_hw_data.c (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1a977168cSMichal Gulbicki /* SPDX-License-Identifier: BSD-3-Clause  */
2a977168cSMichal Gulbicki /* Copyright(c) 2021 Intel Corporation */
3a977168cSMichal Gulbicki #include "adf_gen2_hw_data.h"
4a977168cSMichal Gulbicki #include "icp_qat_hw.h"
5a977168cSMichal Gulbicki 
6a977168cSMichal Gulbicki static u64
build_csr_ring_base_addr(bus_addr_t addr,u32 size)7a977168cSMichal Gulbicki build_csr_ring_base_addr(bus_addr_t addr, u32 size)
8a977168cSMichal Gulbicki {
9a977168cSMichal Gulbicki 	return BUILD_RING_BASE_ADDR(addr, size);
10a977168cSMichal Gulbicki }
11a977168cSMichal Gulbicki 
12a977168cSMichal Gulbicki static u32
read_csr_ring_head(struct resource * csr_base_addr,u32 bank,u32 ring)13a977168cSMichal Gulbicki read_csr_ring_head(struct resource *csr_base_addr, u32 bank, u32 ring)
14a977168cSMichal Gulbicki {
15a977168cSMichal Gulbicki 	return READ_CSR_RING_HEAD(csr_base_addr, bank, ring);
16a977168cSMichal Gulbicki }
17a977168cSMichal Gulbicki 
18a977168cSMichal Gulbicki static void
write_csr_ring_head(struct resource * csr_base_addr,u32 bank,u32 ring,u32 value)19a977168cSMichal Gulbicki write_csr_ring_head(struct resource *csr_base_addr,
20a977168cSMichal Gulbicki 		    u32 bank,
21a977168cSMichal Gulbicki 		    u32 ring,
22a977168cSMichal Gulbicki 		    u32 value)
23a977168cSMichal Gulbicki {
24a977168cSMichal Gulbicki 	WRITE_CSR_RING_HEAD(csr_base_addr, bank, ring, value);
25a977168cSMichal Gulbicki }
26a977168cSMichal Gulbicki 
27a977168cSMichal Gulbicki static u32
read_csr_ring_tail(struct resource * csr_base_addr,u32 bank,u32 ring)28a977168cSMichal Gulbicki read_csr_ring_tail(struct resource *csr_base_addr, u32 bank, u32 ring)
29a977168cSMichal Gulbicki {
30a977168cSMichal Gulbicki 	return READ_CSR_RING_TAIL(csr_base_addr, bank, ring);
31a977168cSMichal Gulbicki }
32a977168cSMichal Gulbicki 
33a977168cSMichal Gulbicki static void
write_csr_ring_tail(struct resource * csr_base_addr,u32 bank,u32 ring,u32 value)34a977168cSMichal Gulbicki write_csr_ring_tail(struct resource *csr_base_addr,
35a977168cSMichal Gulbicki 		    u32 bank,
36a977168cSMichal Gulbicki 		    u32 ring,
37a977168cSMichal Gulbicki 		    u32 value)
38a977168cSMichal Gulbicki {
39a977168cSMichal Gulbicki 	WRITE_CSR_RING_TAIL(csr_base_addr, bank, ring, value);
40a977168cSMichal Gulbicki }
41a977168cSMichal Gulbicki 
42a977168cSMichal Gulbicki static u32
read_csr_e_stat(struct resource * csr_base_addr,u32 bank)43a977168cSMichal Gulbicki read_csr_e_stat(struct resource *csr_base_addr, u32 bank)
44a977168cSMichal Gulbicki {
45a977168cSMichal Gulbicki 	return READ_CSR_E_STAT(csr_base_addr, bank);
46a977168cSMichal Gulbicki }
47a977168cSMichal Gulbicki 
48a977168cSMichal Gulbicki static void
write_csr_ring_config(struct resource * csr_base_addr,u32 bank,u32 ring,u32 value)49a977168cSMichal Gulbicki write_csr_ring_config(struct resource *csr_base_addr,
50a977168cSMichal Gulbicki 		      u32 bank,
51a977168cSMichal Gulbicki 		      u32 ring,
52a977168cSMichal Gulbicki 		      u32 value)
53a977168cSMichal Gulbicki {
54a977168cSMichal Gulbicki 	WRITE_CSR_RING_CONFIG(csr_base_addr, bank, ring, value);
55a977168cSMichal Gulbicki }
56a977168cSMichal Gulbicki 
57*266b0663SKrzysztof Zdziarski static dma_addr_t
read_csr_ring_base(struct resource * csr_base_addr,u32 bank,u32 ring)58*266b0663SKrzysztof Zdziarski read_csr_ring_base(struct resource *csr_base_addr, u32 bank, u32 ring)
59*266b0663SKrzysztof Zdziarski {
60*266b0663SKrzysztof Zdziarski 	return READ_CSR_RING_BASE(csr_base_addr, bank, ring);
61*266b0663SKrzysztof Zdziarski }
62*266b0663SKrzysztof Zdziarski 
63a977168cSMichal Gulbicki static void
write_csr_ring_base(struct resource * csr_base_addr,u32 bank,u32 ring,bus_addr_t addr)64a977168cSMichal Gulbicki write_csr_ring_base(struct resource *csr_base_addr,
65a977168cSMichal Gulbicki 		    u32 bank,
66a977168cSMichal Gulbicki 		    u32 ring,
67a977168cSMichal Gulbicki 		    bus_addr_t addr)
68a977168cSMichal Gulbicki {
69a977168cSMichal Gulbicki 	WRITE_CSR_RING_BASE(csr_base_addr, bank, ring, addr);
70a977168cSMichal Gulbicki }
71a977168cSMichal Gulbicki 
72a977168cSMichal Gulbicki static void
write_csr_int_flag(struct resource * csr_base_addr,u32 bank,u32 value)73a977168cSMichal Gulbicki write_csr_int_flag(struct resource *csr_base_addr, u32 bank, u32 value)
74a977168cSMichal Gulbicki {
75a977168cSMichal Gulbicki 	WRITE_CSR_INT_FLAG(csr_base_addr, bank, value);
76a977168cSMichal Gulbicki }
77a977168cSMichal Gulbicki 
78a977168cSMichal Gulbicki static void
write_csr_int_srcsel(struct resource * csr_base_addr,u32 bank)79a977168cSMichal Gulbicki write_csr_int_srcsel(struct resource *csr_base_addr, u32 bank)
80a977168cSMichal Gulbicki {
81a977168cSMichal Gulbicki 	WRITE_CSR_INT_SRCSEL(csr_base_addr, bank);
82a977168cSMichal Gulbicki }
83a977168cSMichal Gulbicki 
84a977168cSMichal Gulbicki static void
write_csr_int_col_en(struct resource * csr_base_addr,u32 bank,u32 value)85a977168cSMichal Gulbicki write_csr_int_col_en(struct resource *csr_base_addr, u32 bank, u32 value)
86a977168cSMichal Gulbicki {
87a977168cSMichal Gulbicki 	WRITE_CSR_INT_COL_EN(csr_base_addr, bank, value);
88a977168cSMichal Gulbicki }
89a977168cSMichal Gulbicki 
90a977168cSMichal Gulbicki static void
write_csr_int_col_ctl(struct resource * csr_base_addr,u32 bank,u32 value)91a977168cSMichal Gulbicki write_csr_int_col_ctl(struct resource *csr_base_addr, u32 bank, u32 value)
92a977168cSMichal Gulbicki {
93a977168cSMichal Gulbicki 	WRITE_CSR_INT_COL_CTL(csr_base_addr, bank, value);
94a977168cSMichal Gulbicki }
95a977168cSMichal Gulbicki 
96a977168cSMichal Gulbicki static void
write_csr_int_flag_and_col(struct resource * csr_base_addr,u32 bank,u32 value)97a977168cSMichal Gulbicki write_csr_int_flag_and_col(struct resource *csr_base_addr, u32 bank, u32 value)
98a977168cSMichal Gulbicki {
99a977168cSMichal Gulbicki 	WRITE_CSR_INT_FLAG_AND_COL(csr_base_addr, bank, value);
100a977168cSMichal Gulbicki }
101a977168cSMichal Gulbicki 
102a977168cSMichal Gulbicki static u32
read_csr_ring_srv_arb_en(struct resource * csr_base_addr,u32 bank)103a977168cSMichal Gulbicki read_csr_ring_srv_arb_en(struct resource *csr_base_addr, u32 bank)
104a977168cSMichal Gulbicki {
105a977168cSMichal Gulbicki 	return READ_CSR_RING_SRV_ARB_EN(csr_base_addr, bank);
106a977168cSMichal Gulbicki }
107a977168cSMichal Gulbicki 
108a977168cSMichal Gulbicki static void
write_csr_ring_srv_arb_en(struct resource * csr_base_addr,u32 bank,u32 value)109a977168cSMichal Gulbicki write_csr_ring_srv_arb_en(struct resource *csr_base_addr, u32 bank, u32 value)
110a977168cSMichal Gulbicki {
111a977168cSMichal Gulbicki 	WRITE_CSR_RING_SRV_ARB_EN(csr_base_addr, bank, value);
112a977168cSMichal Gulbicki }
113a977168cSMichal Gulbicki 
114*266b0663SKrzysztof Zdziarski static u32
get_int_col_ctl_enable_mask(void)115*266b0663SKrzysztof Zdziarski get_int_col_ctl_enable_mask(void)
116*266b0663SKrzysztof Zdziarski {
117*266b0663SKrzysztof Zdziarski 	return ADF_RING_CSR_INT_COL_CTL_ENABLE;
118*266b0663SKrzysztof Zdziarski }
119*266b0663SKrzysztof Zdziarski 
120a977168cSMichal Gulbicki void
adf_gen2_init_hw_csr_info(struct adf_hw_csr_info * csr_info)121a977168cSMichal Gulbicki adf_gen2_init_hw_csr_info(struct adf_hw_csr_info *csr_info)
122a977168cSMichal Gulbicki {
123a977168cSMichal Gulbicki 	struct adf_hw_csr_ops *csr_ops = &csr_info->csr_ops;
124a977168cSMichal Gulbicki 
125a977168cSMichal Gulbicki 	csr_info->arb_enable_mask = 0xFF;
126a977168cSMichal Gulbicki 
127*266b0663SKrzysztof Zdziarski 	csr_info->csr_addr_offset = ADF_RING_CSR_ADDR_OFFSET;
128*266b0663SKrzysztof Zdziarski 	csr_info->ring_bundle_size = ADF_RING_BUNDLE_SIZE;
129*266b0663SKrzysztof Zdziarski 
130a977168cSMichal Gulbicki 	csr_ops->build_csr_ring_base_addr = build_csr_ring_base_addr;
131a977168cSMichal Gulbicki 	csr_ops->read_csr_ring_head = read_csr_ring_head;
132a977168cSMichal Gulbicki 	csr_ops->write_csr_ring_head = write_csr_ring_head;
133a977168cSMichal Gulbicki 	csr_ops->read_csr_ring_tail = read_csr_ring_tail;
134a977168cSMichal Gulbicki 	csr_ops->write_csr_ring_tail = write_csr_ring_tail;
135a977168cSMichal Gulbicki 	csr_ops->read_csr_e_stat = read_csr_e_stat;
136a977168cSMichal Gulbicki 	csr_ops->write_csr_ring_config = write_csr_ring_config;
137*266b0663SKrzysztof Zdziarski 	csr_ops->read_csr_ring_base = read_csr_ring_base;
138a977168cSMichal Gulbicki 	csr_ops->write_csr_ring_base = write_csr_ring_base;
139a977168cSMichal Gulbicki 	csr_ops->write_csr_int_flag = write_csr_int_flag;
140a977168cSMichal Gulbicki 	csr_ops->write_csr_int_srcsel = write_csr_int_srcsel;
141a977168cSMichal Gulbicki 	csr_ops->write_csr_int_col_en = write_csr_int_col_en;
142a977168cSMichal Gulbicki 	csr_ops->write_csr_int_col_ctl = write_csr_int_col_ctl;
143a977168cSMichal Gulbicki 	csr_ops->write_csr_int_flag_and_col = write_csr_int_flag_and_col;
144a977168cSMichal Gulbicki 	csr_ops->read_csr_ring_srv_arb_en = read_csr_ring_srv_arb_en;
145a977168cSMichal Gulbicki 	csr_ops->write_csr_ring_srv_arb_en = write_csr_ring_srv_arb_en;
146*266b0663SKrzysztof Zdziarski 	csr_ops->get_int_col_ctl_enable_mask = get_int_col_ctl_enable_mask;
147a977168cSMichal Gulbicki }
148