.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Huawei HiNIC PCI Express Linux driver |
---|
3 | 4 | * Copyright(c) 2017 Huawei Technologies Co., Ltd |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify it |
---|
6 | | - * under the terms and conditions of the GNU General Public License, |
---|
7 | | - * version 2, as published by the Free Software Foundation. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
---|
10 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
11 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
12 | | - * for more details. |
---|
13 | | - * |
---|
14 | 5 | */ |
---|
15 | 6 | |
---|
16 | 7 | #ifndef HINIC_HW_IF_H |
---|
.. | .. |
---|
20 | 11 | #include <linux/io.h> |
---|
21 | 12 | #include <linux/types.h> |
---|
22 | 13 | #include <asm/byteorder.h> |
---|
| 14 | + |
---|
| 15 | +#define HINIC_PCIE_LINK_DOWN 0xFFFFFFFF |
---|
23 | 16 | |
---|
24 | 17 | #define HINIC_DMA_ATTR_ST_SHIFT 0 |
---|
25 | 18 | #define HINIC_DMA_ATTR_AT_SHIFT 8 |
---|
.. | .. |
---|
44 | 37 | #define HINIC_FA0_FUNC_IDX_SHIFT 0 |
---|
45 | 38 | #define HINIC_FA0_PF_IDX_SHIFT 10 |
---|
46 | 39 | #define HINIC_FA0_PCI_INTF_IDX_SHIFT 14 |
---|
| 40 | +#define HINIC_FA0_VF_IN_PF_SHIFT 16 |
---|
47 | 41 | /* reserved members - off 16 */ |
---|
48 | 42 | #define HINIC_FA0_FUNC_TYPE_SHIFT 24 |
---|
49 | 43 | |
---|
.. | .. |
---|
51 | 45 | #define HINIC_FA0_PF_IDX_MASK 0xF |
---|
52 | 46 | #define HINIC_FA0_PCI_INTF_IDX_MASK 0x3 |
---|
53 | 47 | #define HINIC_FA0_FUNC_TYPE_MASK 0x1 |
---|
| 48 | +#define HINIC_FA0_VF_IN_PF_MASK 0xFF |
---|
54 | 49 | |
---|
55 | 50 | #define HINIC_FA0_GET(val, member) \ |
---|
56 | 51 | (((val) >> HINIC_FA0_##member##_SHIFT) & HINIC_FA0_##member##_MASK) |
---|
.. | .. |
---|
62 | 57 | #define HINIC_FA1_IRQS_PER_FUNC_SHIFT 20 |
---|
63 | 58 | #define HINIC_FA1_DMA_ATTR_PER_FUNC_SHIFT 24 |
---|
64 | 59 | /* reserved members - off 27 */ |
---|
65 | | -#define HINIC_FA1_INIT_STATUS_SHIFT 30 |
---|
| 60 | +#define HINIC_FA1_MGMT_INIT_STATUS_SHIFT 30 |
---|
| 61 | +#define HINIC_FA1_PF_INIT_STATUS_SHIFT 31 |
---|
66 | 62 | |
---|
67 | 63 | #define HINIC_FA1_AEQS_PER_FUNC_MASK 0x3 |
---|
68 | 64 | #define HINIC_FA1_CEQS_PER_FUNC_MASK 0x7 |
---|
69 | 65 | #define HINIC_FA1_IRQS_PER_FUNC_MASK 0xF |
---|
70 | 66 | #define HINIC_FA1_DMA_ATTR_PER_FUNC_MASK 0x7 |
---|
71 | | -#define HINIC_FA1_INIT_STATUS_MASK 0x1 |
---|
| 67 | +#define HINIC_FA1_MGMT_INIT_STATUS_MASK 0x1 |
---|
| 68 | +#define HINIC_FA1_PF_INIT_STATUS_MASK 0x1 |
---|
72 | 69 | |
---|
73 | 70 | #define HINIC_FA1_GET(val, member) \ |
---|
74 | 71 | (((val) >> HINIC_FA1_##member##_SHIFT) & HINIC_FA1_##member##_MASK) |
---|
| 72 | + |
---|
| 73 | +#define HINIC_FA2_GLOBAL_VF_ID_OF_PF_SHIFT 16 |
---|
| 74 | +#define HINIC_FA2_GLOBAL_VF_ID_OF_PF_MASK 0x3FF |
---|
| 75 | + |
---|
| 76 | +#define HINIC_FA2_GET(val, member) \ |
---|
| 77 | + (((val) >> HINIC_FA2_##member##_SHIFT) & HINIC_FA2_##member##_MASK) |
---|
75 | 78 | |
---|
76 | 79 | #define HINIC_FA4_OUTBOUND_STATE_SHIFT 0 |
---|
77 | 80 | #define HINIC_FA4_DB_STATE_SHIFT 1 |
---|
.. | .. |
---|
149 | 152 | #define HINIC_HWIF_PPF_IDX(hwif) ((hwif)->attr.ppf_idx) |
---|
150 | 153 | |
---|
151 | 154 | #define HINIC_FUNC_TYPE(hwif) ((hwif)->attr.func_type) |
---|
| 155 | +#define HINIC_IS_VF(hwif) (HINIC_FUNC_TYPE(hwif) == HINIC_VF) |
---|
152 | 156 | #define HINIC_IS_PF(hwif) (HINIC_FUNC_TYPE(hwif) == HINIC_PF) |
---|
153 | 157 | #define HINIC_IS_PPF(hwif) (HINIC_FUNC_TYPE(hwif) == HINIC_PPF) |
---|
154 | 158 | |
---|
155 | 159 | #define HINIC_PCI_CFG_REGS_BAR 0 |
---|
| 160 | +#define HINIC_PCI_INTR_REGS_BAR 2 |
---|
156 | 161 | #define HINIC_PCI_DB_BAR 4 |
---|
157 | 162 | |
---|
158 | 163 | #define HINIC_PCIE_ST_DISABLE 0 |
---|
.. | .. |
---|
164 | 169 | #define HINIC_EQ_MSIX_LLI_TIMER_DEFAULT 0 /* Disabled */ |
---|
165 | 170 | #define HINIC_EQ_MSIX_LLI_CREDIT_LIMIT_DEFAULT 0 /* Disabled */ |
---|
166 | 171 | #define HINIC_EQ_MSIX_RESEND_TIMER_DEFAULT 7 /* max */ |
---|
| 172 | + |
---|
| 173 | +#define HINIC_PCI_MSIX_ENTRY_SIZE 16 |
---|
| 174 | +#define HINIC_PCI_MSIX_ENTRY_VECTOR_CTRL 12 |
---|
| 175 | +#define HINIC_PCI_MSIX_ENTRY_CTRL_MASKBIT 1 |
---|
167 | 176 | |
---|
168 | 177 | enum hinic_pcie_nosnoop { |
---|
169 | 178 | HINIC_PCIE_SNOOP = 0, |
---|
.. | .. |
---|
177 | 186 | |
---|
178 | 187 | enum hinic_func_type { |
---|
179 | 188 | HINIC_PF = 0, |
---|
| 189 | + HINIC_VF = 1, |
---|
180 | 190 | HINIC_PPF = 2, |
---|
181 | 191 | }; |
---|
182 | 192 | |
---|
.. | .. |
---|
184 | 194 | HINIC_MOD_COMM = 0, /* HW communication module */ |
---|
185 | 195 | HINIC_MOD_L2NIC = 1, /* L2NIC module */ |
---|
186 | 196 | HINIC_MOD_CFGM = 7, /* Configuration module */ |
---|
187 | | - |
---|
| 197 | + HINIC_MOD_HILINK = 14, /* Hilink module */ |
---|
188 | 198 | HINIC_MOD_MAX = 15 |
---|
189 | 199 | }; |
---|
190 | 200 | |
---|
.. | .. |
---|
208 | 218 | HINIC_DB_DISABLE = 1, |
---|
209 | 219 | }; |
---|
210 | 220 | |
---|
| 221 | +enum hinic_msix_state { |
---|
| 222 | + HINIC_MSIX_ENABLE, |
---|
| 223 | + HINIC_MSIX_DISABLE, |
---|
| 224 | +}; |
---|
| 225 | + |
---|
211 | 226 | struct hinic_func_attr { |
---|
212 | 227 | u16 func_idx; |
---|
213 | 228 | u8 pf_idx; |
---|
.. | .. |
---|
222 | 237 | u8 num_ceqs; |
---|
223 | 238 | |
---|
224 | 239 | u8 num_dma_attr; |
---|
| 240 | + |
---|
| 241 | + u16 global_vf_id_of_pf; |
---|
225 | 242 | }; |
---|
226 | 243 | |
---|
227 | 244 | struct hinic_hwif { |
---|
228 | 245 | struct pci_dev *pdev; |
---|
229 | 246 | void __iomem *cfg_regs_bar; |
---|
| 247 | + void __iomem *intr_regs_base; |
---|
230 | 248 | |
---|
231 | 249 | struct hinic_func_attr attr; |
---|
232 | 250 | }; |
---|
233 | 251 | |
---|
234 | 252 | static inline u32 hinic_hwif_read_reg(struct hinic_hwif *hwif, u32 reg) |
---|
235 | 253 | { |
---|
236 | | - return be32_to_cpu(readl(hwif->cfg_regs_bar + reg)); |
---|
| 254 | + u32 out = readl(hwif->cfg_regs_bar + reg); |
---|
| 255 | + |
---|
| 256 | + return be32_to_cpu(*(__be32 *)&out); |
---|
237 | 257 | } |
---|
238 | 258 | |
---|
239 | 259 | static inline void hinic_hwif_write_reg(struct hinic_hwif *hwif, u32 reg, |
---|
240 | 260 | u32 val) |
---|
241 | 261 | { |
---|
242 | | - writel(cpu_to_be32(val), hwif->cfg_regs_bar + reg); |
---|
| 262 | + __be32 in = cpu_to_be32(val); |
---|
| 263 | + |
---|
| 264 | + writel(*(u32 *)&in, hwif->cfg_regs_bar + reg); |
---|
243 | 265 | } |
---|
244 | 266 | |
---|
245 | 267 | int hinic_msix_attr_set(struct hinic_hwif *hwif, u16 msix_index, |
---|
.. | .. |
---|
251 | 273 | u8 *pending_limit, u8 *coalesc_timer_cfg, |
---|
252 | 274 | u8 *lli_timer, u8 *lli_credit_limit, |
---|
253 | 275 | u8 *resend_timer); |
---|
| 276 | + |
---|
| 277 | +void hinic_set_msix_state(struct hinic_hwif *hwif, u16 msix_idx, |
---|
| 278 | + enum hinic_msix_state flag); |
---|
254 | 279 | |
---|
255 | 280 | int hinic_msix_attr_cnt_clear(struct hinic_hwif *hwif, u16 msix_index); |
---|
256 | 281 | |
---|
.. | .. |
---|
266 | 291 | void hinic_db_state_set(struct hinic_hwif *hwif, |
---|
267 | 292 | enum hinic_db_state db_state); |
---|
268 | 293 | |
---|
| 294 | +u16 hinic_glb_pf_vf_offset(struct hinic_hwif *hwif); |
---|
| 295 | + |
---|
| 296 | +u16 hinic_global_func_id_hw(struct hinic_hwif *hwif); |
---|
| 297 | + |
---|
| 298 | +u16 hinic_pf_id_of_vf_hw(struct hinic_hwif *hwif); |
---|
| 299 | + |
---|
269 | 300 | int hinic_init_hwif(struct hinic_hwif *hwif, struct pci_dev *pdev); |
---|
270 | 301 | |
---|
271 | 302 | void hinic_free_hwif(struct hinic_hwif *hwif); |
---|