This source file includes following definitions.
- hinic_hwif_read_reg
- hinic_hwif_write_reg
1
2
3
4
5
6
7 #ifndef HINIC_HW_IF_H
8 #define HINIC_HW_IF_H
9
10 #include <linux/pci.h>
11 #include <linux/io.h>
12 #include <linux/types.h>
13 #include <asm/byteorder.h>
14
15 #define HINIC_DMA_ATTR_ST_SHIFT 0
16 #define HINIC_DMA_ATTR_AT_SHIFT 8
17 #define HINIC_DMA_ATTR_PH_SHIFT 10
18 #define HINIC_DMA_ATTR_NO_SNOOPING_SHIFT 12
19 #define HINIC_DMA_ATTR_TPH_EN_SHIFT 13
20
21 #define HINIC_DMA_ATTR_ST_MASK 0xFF
22 #define HINIC_DMA_ATTR_AT_MASK 0x3
23 #define HINIC_DMA_ATTR_PH_MASK 0x3
24 #define HINIC_DMA_ATTR_NO_SNOOPING_MASK 0x1
25 #define HINIC_DMA_ATTR_TPH_EN_MASK 0x1
26
27 #define HINIC_DMA_ATTR_SET(val, member) \
28 (((u32)(val) & HINIC_DMA_ATTR_##member##_MASK) << \
29 HINIC_DMA_ATTR_##member##_SHIFT)
30
31 #define HINIC_DMA_ATTR_CLEAR(val, member) \
32 ((val) & (~(HINIC_DMA_ATTR_##member##_MASK \
33 << HINIC_DMA_ATTR_##member##_SHIFT)))
34
35 #define HINIC_FA0_FUNC_IDX_SHIFT 0
36 #define HINIC_FA0_PF_IDX_SHIFT 10
37 #define HINIC_FA0_PCI_INTF_IDX_SHIFT 14
38
39 #define HINIC_FA0_FUNC_TYPE_SHIFT 24
40
41 #define HINIC_FA0_FUNC_IDX_MASK 0x3FF
42 #define HINIC_FA0_PF_IDX_MASK 0xF
43 #define HINIC_FA0_PCI_INTF_IDX_MASK 0x3
44 #define HINIC_FA0_FUNC_TYPE_MASK 0x1
45
46 #define HINIC_FA0_GET(val, member) \
47 (((val) >> HINIC_FA0_##member##_SHIFT) & HINIC_FA0_##member##_MASK)
48
49 #define HINIC_FA1_AEQS_PER_FUNC_SHIFT 8
50
51 #define HINIC_FA1_CEQS_PER_FUNC_SHIFT 12
52
53 #define HINIC_FA1_IRQS_PER_FUNC_SHIFT 20
54 #define HINIC_FA1_DMA_ATTR_PER_FUNC_SHIFT 24
55
56 #define HINIC_FA1_INIT_STATUS_SHIFT 30
57
58 #define HINIC_FA1_AEQS_PER_FUNC_MASK 0x3
59 #define HINIC_FA1_CEQS_PER_FUNC_MASK 0x7
60 #define HINIC_FA1_IRQS_PER_FUNC_MASK 0xF
61 #define HINIC_FA1_DMA_ATTR_PER_FUNC_MASK 0x7
62 #define HINIC_FA1_INIT_STATUS_MASK 0x1
63
64 #define HINIC_FA1_GET(val, member) \
65 (((val) >> HINIC_FA1_##member##_SHIFT) & HINIC_FA1_##member##_MASK)
66
67 #define HINIC_FA4_OUTBOUND_STATE_SHIFT 0
68 #define HINIC_FA4_DB_STATE_SHIFT 1
69
70 #define HINIC_FA4_OUTBOUND_STATE_MASK 0x1
71 #define HINIC_FA4_DB_STATE_MASK 0x1
72
73 #define HINIC_FA4_GET(val, member) \
74 (((val) >> HINIC_FA4_##member##_SHIFT) & HINIC_FA4_##member##_MASK)
75
76 #define HINIC_FA4_SET(val, member) \
77 ((((u32)val) & HINIC_FA4_##member##_MASK) << HINIC_FA4_##member##_SHIFT)
78
79 #define HINIC_FA4_CLEAR(val, member) \
80 ((val) & (~(HINIC_FA4_##member##_MASK << HINIC_FA4_##member##_SHIFT)))
81
82 #define HINIC_FA5_PF_ACTION_SHIFT 0
83 #define HINIC_FA5_PF_ACTION_MASK 0xFFFF
84
85 #define HINIC_FA5_SET(val, member) \
86 (((u32)(val) & HINIC_FA5_##member##_MASK) << HINIC_FA5_##member##_SHIFT)
87
88 #define HINIC_FA5_CLEAR(val, member) \
89 ((val) & (~(HINIC_FA5_##member##_MASK << HINIC_FA5_##member##_SHIFT)))
90
91 #define HINIC_PPF_ELECTION_IDX_SHIFT 0
92 #define HINIC_PPF_ELECTION_IDX_MASK 0x1F
93
94 #define HINIC_PPF_ELECTION_SET(val, member) \
95 (((u32)(val) & HINIC_PPF_ELECTION_##member##_MASK) << \
96 HINIC_PPF_ELECTION_##member##_SHIFT)
97
98 #define HINIC_PPF_ELECTION_GET(val, member) \
99 (((val) >> HINIC_PPF_ELECTION_##member##_SHIFT) & \
100 HINIC_PPF_ELECTION_##member##_MASK)
101
102 #define HINIC_PPF_ELECTION_CLEAR(val, member) \
103 ((val) & (~(HINIC_PPF_ELECTION_##member##_MASK \
104 << HINIC_PPF_ELECTION_##member##_SHIFT)))
105
106 #define HINIC_MSIX_PENDING_LIMIT_SHIFT 0
107 #define HINIC_MSIX_COALESC_TIMER_SHIFT 8
108 #define HINIC_MSIX_LLI_TIMER_SHIFT 16
109 #define HINIC_MSIX_LLI_CREDIT_SHIFT 24
110 #define HINIC_MSIX_RESEND_TIMER_SHIFT 29
111
112 #define HINIC_MSIX_PENDING_LIMIT_MASK 0xFF
113 #define HINIC_MSIX_COALESC_TIMER_MASK 0xFF
114 #define HINIC_MSIX_LLI_TIMER_MASK 0xFF
115 #define HINIC_MSIX_LLI_CREDIT_MASK 0x1F
116 #define HINIC_MSIX_RESEND_TIMER_MASK 0x7
117
118 #define HINIC_MSIX_ATTR_SET(val, member) \
119 (((u32)(val) & HINIC_MSIX_##member##_MASK) << \
120 HINIC_MSIX_##member##_SHIFT)
121
122 #define HINIC_MSIX_ATTR_GET(val, member) \
123 (((val) >> HINIC_MSIX_##member##_SHIFT) & \
124 HINIC_MSIX_##member##_MASK)
125
126 #define HINIC_MSIX_CNT_RESEND_TIMER_SHIFT 29
127
128 #define HINIC_MSIX_CNT_RESEND_TIMER_MASK 0x1
129
130 #define HINIC_MSIX_CNT_SET(val, member) \
131 (((u32)(val) & HINIC_MSIX_CNT_##member##_MASK) << \
132 HINIC_MSIX_CNT_##member##_SHIFT)
133
134 #define HINIC_HWIF_NUM_AEQS(hwif) ((hwif)->attr.num_aeqs)
135 #define HINIC_HWIF_NUM_CEQS(hwif) ((hwif)->attr.num_ceqs)
136 #define HINIC_HWIF_NUM_IRQS(hwif) ((hwif)->attr.num_irqs)
137 #define HINIC_HWIF_FUNC_IDX(hwif) ((hwif)->attr.func_idx)
138 #define HINIC_HWIF_PCI_INTF(hwif) ((hwif)->attr.pci_intf_idx)
139 #define HINIC_HWIF_PF_IDX(hwif) ((hwif)->attr.pf_idx)
140 #define HINIC_HWIF_PPF_IDX(hwif) ((hwif)->attr.ppf_idx)
141
142 #define HINIC_FUNC_TYPE(hwif) ((hwif)->attr.func_type)
143 #define HINIC_IS_PF(hwif) (HINIC_FUNC_TYPE(hwif) == HINIC_PF)
144 #define HINIC_IS_PPF(hwif) (HINIC_FUNC_TYPE(hwif) == HINIC_PPF)
145
146 #define HINIC_PCI_CFG_REGS_BAR 0
147 #define HINIC_PCI_INTR_REGS_BAR 2
148 #define HINIC_PCI_DB_BAR 4
149
150 #define HINIC_PCIE_ST_DISABLE 0
151 #define HINIC_PCIE_AT_DISABLE 0
152 #define HINIC_PCIE_PH_DISABLE 0
153
154 #define HINIC_EQ_MSIX_PENDING_LIMIT_DEFAULT 0
155 #define HINIC_EQ_MSIX_COALESC_TIMER_DEFAULT 0xFF
156 #define HINIC_EQ_MSIX_LLI_TIMER_DEFAULT 0
157 #define HINIC_EQ_MSIX_LLI_CREDIT_LIMIT_DEFAULT 0
158 #define HINIC_EQ_MSIX_RESEND_TIMER_DEFAULT 7
159
160 #define HINIC_PCI_MSIX_ENTRY_SIZE 16
161 #define HINIC_PCI_MSIX_ENTRY_VECTOR_CTRL 12
162 #define HINIC_PCI_MSIX_ENTRY_CTRL_MASKBIT 1
163
164 enum hinic_pcie_nosnoop {
165 HINIC_PCIE_SNOOP = 0,
166 HINIC_PCIE_NO_SNOOP = 1,
167 };
168
169 enum hinic_pcie_tph {
170 HINIC_PCIE_TPH_DISABLE = 0,
171 HINIC_PCIE_TPH_ENABLE = 1,
172 };
173
174 enum hinic_func_type {
175 HINIC_PF = 0,
176 HINIC_PPF = 2,
177 };
178
179 enum hinic_mod_type {
180 HINIC_MOD_COMM = 0,
181 HINIC_MOD_L2NIC = 1,
182 HINIC_MOD_CFGM = 7,
183
184 HINIC_MOD_MAX = 15
185 };
186
187 enum hinic_node_id {
188 HINIC_NODE_ID_MGMT = 21,
189 };
190
191 enum hinic_pf_action {
192 HINIC_PF_MGMT_INIT = 0x0,
193
194 HINIC_PF_MGMT_ACTIVE = 0x11,
195 };
196
197 enum hinic_outbound_state {
198 HINIC_OUTBOUND_ENABLE = 0,
199 HINIC_OUTBOUND_DISABLE = 1,
200 };
201
202 enum hinic_db_state {
203 HINIC_DB_ENABLE = 0,
204 HINIC_DB_DISABLE = 1,
205 };
206
207 enum hinic_msix_state {
208 HINIC_MSIX_ENABLE,
209 HINIC_MSIX_DISABLE,
210 };
211
212 struct hinic_func_attr {
213 u16 func_idx;
214 u8 pf_idx;
215 u8 pci_intf_idx;
216
217 enum hinic_func_type func_type;
218
219 u8 ppf_idx;
220
221 u16 num_irqs;
222 u8 num_aeqs;
223 u8 num_ceqs;
224
225 u8 num_dma_attr;
226 };
227
228 struct hinic_hwif {
229 struct pci_dev *pdev;
230 void __iomem *cfg_regs_bar;
231 void __iomem *intr_regs_base;
232
233 struct hinic_func_attr attr;
234 };
235
236 static inline u32 hinic_hwif_read_reg(struct hinic_hwif *hwif, u32 reg)
237 {
238 return be32_to_cpu(readl(hwif->cfg_regs_bar + reg));
239 }
240
241 static inline void hinic_hwif_write_reg(struct hinic_hwif *hwif, u32 reg,
242 u32 val)
243 {
244 writel(cpu_to_be32(val), hwif->cfg_regs_bar + reg);
245 }
246
247 int hinic_msix_attr_set(struct hinic_hwif *hwif, u16 msix_index,
248 u8 pending_limit, u8 coalesc_timer,
249 u8 lli_timer_cfg, u8 lli_credit_limit,
250 u8 resend_timer);
251
252 int hinic_msix_attr_get(struct hinic_hwif *hwif, u16 msix_index,
253 u8 *pending_limit, u8 *coalesc_timer_cfg,
254 u8 *lli_timer, u8 *lli_credit_limit,
255 u8 *resend_timer);
256
257 void hinic_set_msix_state(struct hinic_hwif *hwif, u16 msix_idx,
258 enum hinic_msix_state flag);
259
260 int hinic_msix_attr_cnt_clear(struct hinic_hwif *hwif, u16 msix_index);
261
262 void hinic_set_pf_action(struct hinic_hwif *hwif, enum hinic_pf_action action);
263
264 enum hinic_outbound_state hinic_outbound_state_get(struct hinic_hwif *hwif);
265
266 void hinic_outbound_state_set(struct hinic_hwif *hwif,
267 enum hinic_outbound_state outbound_state);
268
269 enum hinic_db_state hinic_db_state_get(struct hinic_hwif *hwif);
270
271 void hinic_db_state_set(struct hinic_hwif *hwif,
272 enum hinic_db_state db_state);
273
274 int hinic_init_hwif(struct hinic_hwif *hwif, struct pci_dev *pdev);
275
276 void hinic_free_hwif(struct hinic_hwif *hwif);
277
278 #endif