Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2019 Intel Corporation.
3 : : */
4 : : #include <stdint.h>
5 : : #include <stdio.h>
6 : : #include <errno.h>
7 : :
8 : : #include <rte_io.h>
9 : : #include <rte_eal.h>
10 : : #include <rte_pci.h>
11 : : #include <bus_pci_driver.h>
12 : : #include <rte_rawdev.h>
13 : : #include <rte_rawdev_pmd.h>
14 : :
15 : : #include "ntb.h"
16 : : #include "ntb_hw_intel.h"
17 : :
18 : : enum xeon_ntb_bar {
19 : : XEON_NTB_BAR23 = 2,
20 : : XEON_NTB_BAR45 = 4,
21 : : };
22 : :
23 : : static enum xeon_ntb_bar intel_ntb_bar[] = {
24 : : XEON_NTB_BAR23,
25 : : XEON_NTB_BAR45,
26 : : };
27 : :
28 : : static inline int
29 : : is_gen3_ntb(const struct ntb_hw *hw)
30 : : {
31 [ # # # # : 0 : if (hw->pci_dev->id.device_id == NTB_INTEL_DEV_ID_B2B_SKX)
# # # # #
# ]
32 : : return 1;
33 : :
34 : : return 0;
35 : : }
36 : :
37 : : static inline int
38 : : is_gen4_ntb(const struct ntb_hw *hw)
39 : : {
40 [ # # # # : 0 : if (hw->pci_dev->id.device_id == NTB_INTEL_DEV_ID_B2B_ICX ||
# # # # #
# # # #
# ]
41 : : hw->pci_dev->id.device_id == NTB_INTEL_DEV_ID_B2B_SPR)
42 : : return 1;
43 : :
44 : : return 0;
45 : : }
46 : :
47 : : static int
48 : 0 : intel_ntb3_check_ppd(struct ntb_hw *hw)
49 : : {
50 : : uint8_t reg_val;
51 : : int ret;
52 : :
53 : 0 : ret = rte_pci_read_config(hw->pci_dev, ®_val,
54 : : sizeof(reg_val), XEON_PPD_OFFSET);
55 [ # # ]: 0 : if (ret < 0) {
56 : 0 : NTB_LOG(ERR, "Cannot get NTB PPD (PCIe port definition).");
57 : 0 : return -EIO;
58 : : }
59 : :
60 : : /* Check connection topo type. Only support B2B. */
61 [ # # ]: 0 : switch (reg_val & XEON_PPD_CONN_MASK) {
62 : 0 : case XEON_PPD_CONN_B2B:
63 : 0 : NTB_LOG(INFO, "Topo B2B (back to back) is using.");
64 : : break;
65 : 0 : case XEON_PPD_CONN_TRANSPARENT:
66 : : case XEON_PPD_CONN_RP:
67 : : default:
68 : 0 : NTB_LOG(ERR, "Not supported conn topo. Please use B2B.");
69 : 0 : return -EINVAL;
70 : : }
71 : :
72 : : /* Check device type. */
73 [ # # ]: 0 : if (reg_val & XEON_PPD_DEV_DSD) {
74 : 0 : NTB_LOG(INFO, "DSD, Downstream Device.");
75 : 0 : hw->topo = NTB_TOPO_B2B_DSD;
76 : : } else {
77 : 0 : NTB_LOG(INFO, "USD, Upstream device.");
78 : 0 : hw->topo = NTB_TOPO_B2B_USD;
79 : : }
80 : :
81 : : /* Check if bar4 is split. Do not support split bar. */
82 [ # # ]: 0 : if (reg_val & XEON_PPD_SPLIT_BAR_MASK) {
83 : 0 : NTB_LOG(ERR, "Do not support split bar.");
84 : 0 : return -EINVAL;
85 : : }
86 : :
87 : : return 0;
88 : : }
89 : :
90 : : static int
91 : 0 : intel_ntb4_check_ppd_for_ICX(struct ntb_hw *hw, uint32_t reg_val)
92 : : {
93 : : /* Check connection topo type. Only support B2B. */
94 [ # # ]: 0 : switch (reg_val & XEON_GEN4_PPD_CONN_MASK) {
95 : 0 : case XEON_GEN4_PPD_CONN_B2B:
96 : 0 : NTB_LOG(INFO, "Topo B2B (back to back) is using.");
97 : : break;
98 : 0 : default:
99 : 0 : NTB_LOG(ERR, "Not supported conn topo. Please use B2B.");
100 : 0 : return -EINVAL;
101 : : }
102 : :
103 : : /* Check device type. */
104 [ # # ]: 0 : if (reg_val & XEON_GEN4_PPD_DEV_DSD) {
105 : 0 : NTB_LOG(INFO, "DSD, Downstream Device.");
106 : 0 : hw->topo = NTB_TOPO_B2B_DSD;
107 : : } else {
108 : 0 : NTB_LOG(INFO, "USD, Upstream device.");
109 : 0 : hw->topo = NTB_TOPO_B2B_USD;
110 : : }
111 : :
112 : : return 0;
113 : : }
114 : :
115 : : static int
116 : 0 : intel_ntb4_check_ppd_for_SPR(struct ntb_hw *hw, uint32_t reg_val)
117 : : {
118 : : /* Check connection topo type. Only support B2B. */
119 [ # # ]: 0 : switch (reg_val & XEON_SPR_PPD_CONN_MASK) {
120 : 0 : case XEON_SPR_PPD_CONN_B2B:
121 : 0 : NTB_LOG(INFO, "Topo B2B (back to back) is using.");
122 : : break;
123 : 0 : default:
124 : 0 : NTB_LOG(ERR, "Not supported conn topo. Please use B2B.");
125 : 0 : return -EINVAL;
126 : : }
127 : :
128 : : /* Check device type. */
129 [ # # ]: 0 : if (reg_val & XEON_SPR_PPD_DEV_DSD) {
130 : 0 : NTB_LOG(INFO, "DSD, Downstream Device.");
131 : 0 : hw->topo = NTB_TOPO_B2B_DSD;
132 : : } else {
133 : 0 : NTB_LOG(INFO, "USD, Upstream device.");
134 : 0 : hw->topo = NTB_TOPO_B2B_USD;
135 : : }
136 : :
137 : : return 0;
138 : : }
139 : :
140 : : static int
141 : 0 : intel_ntb4_check_ppd(struct ntb_hw *hw)
142 : : {
143 : : uint8_t revision_id;
144 : : uint32_t reg_val;
145 : : int ret;
146 : :
147 : 0 : ret = rte_pci_read_config(hw->pci_dev, &revision_id,
148 : : 1, RTE_PCI_REVISION_ID);
149 [ # # ]: 0 : if (ret != 1) {
150 : 0 : NTB_LOG(ERR, "Cannot get NTB PCI Device Revision ID.");
151 : 0 : return -EIO;
152 : : }
153 : :
154 : 0 : reg_val = rte_read32(hw->hw_addr + XEON_GEN4_PPD1_OFFSET);
155 : :
156 : : /* Distinguish HW platform (ICX/SPR) via PCI Revision ID */
157 [ # # ]: 0 : if (revision_id > NTB_PCI_DEV_REVISION_ICX_MAX)
158 : 0 : ret = intel_ntb4_check_ppd_for_SPR(hw, reg_val);
159 [ # # ]: 0 : else if (revision_id >= NTB_PCI_DEV_REVISION_ICX_MIN)
160 : 0 : ret = intel_ntb4_check_ppd_for_ICX(hw, reg_val);
161 : : else {
162 : 0 : NTB_LOG(ERR, "Invalid NTB PCI Device Revision ID.");
163 : 0 : return -EIO;
164 : : }
165 : :
166 : : return ret;
167 : : }
168 : :
169 : : static int
170 : 0 : intel_ntb_dev_init(const struct rte_rawdev *dev)
171 : : {
172 : 0 : struct ntb_hw *hw = dev->dev_private;
173 : : uint8_t bar;
174 : : int ret, i;
175 : :
176 [ # # ]: 0 : if (hw == NULL) {
177 : 0 : NTB_LOG(ERR, "Invalid device.");
178 : 0 : return -EINVAL;
179 : : }
180 : :
181 [ # # ]: 0 : hw->hw_addr = (char *)hw->pci_dev->mem_resource[0].addr;
182 : :
183 : : if (is_gen3_ntb(hw))
184 : 0 : ret = intel_ntb3_check_ppd(hw);
185 : : else if (is_gen4_ntb(hw))
186 : : /* PPD is in MMIO but not config space for NTB Gen4 */
187 : 0 : ret = intel_ntb4_check_ppd(hw);
188 : : else {
189 : 0 : NTB_LOG(ERR, "Cannot init device for unsupported device.");
190 : 0 : return -ENOTSUP;
191 : : }
192 : :
193 [ # # ]: 0 : if (ret)
194 : : return ret;
195 : :
196 : 0 : hw->mw_cnt = XEON_MW_COUNT;
197 : 0 : hw->db_cnt = XEON_DB_COUNT;
198 : 0 : hw->spad_cnt = XEON_SPAD_COUNT;
199 : :
200 : 0 : hw->mw_size = rte_zmalloc("ntb_mw_size",
201 : : hw->mw_cnt * sizeof(uint64_t), 0);
202 [ # # ]: 0 : if (hw->mw_size == NULL) {
203 : 0 : NTB_LOG(ERR, "Cannot allocate memory for mw size.");
204 : 0 : return -ENOMEM;
205 : : }
206 : :
207 [ # # ]: 0 : for (i = 0; i < hw->mw_cnt; i++) {
208 : 0 : bar = intel_ntb_bar[i];
209 : 0 : hw->mw_size[i] = hw->pci_dev->mem_resource[bar].len;
210 : : }
211 : :
212 : : /* Reserve the last 2 spad registers for users. */
213 [ # # ]: 0 : for (i = 0; i < NTB_SPAD_USER_MAX_NUM; i++)
214 : 0 : hw->spad_user_list[i] = hw->spad_cnt;
215 : 0 : hw->spad_user_list[0] = hw->spad_cnt - 2;
216 : 0 : hw->spad_user_list[1] = hw->spad_cnt - 1;
217 : :
218 : 0 : return 0;
219 : : }
220 : :
221 : : static void *
222 : 0 : intel_ntb_get_peer_mw_addr(const struct rte_rawdev *dev, int mw_idx)
223 : : {
224 : 0 : struct ntb_hw *hw = dev->dev_private;
225 : : uint8_t bar;
226 : :
227 [ # # ]: 0 : if (hw == NULL) {
228 : 0 : NTB_LOG(ERR, "Invalid device.");
229 : 0 : return 0;
230 : : }
231 : :
232 [ # # # # ]: 0 : if (mw_idx < 0 || mw_idx >= hw->mw_cnt) {
233 : 0 : NTB_LOG(ERR, "Invalid memory window index (0 - %u).",
234 : : hw->mw_cnt - 1);
235 : 0 : return 0;
236 : : }
237 : :
238 : 0 : bar = intel_ntb_bar[mw_idx];
239 : :
240 : 0 : return hw->pci_dev->mem_resource[bar].addr;
241 : : }
242 : :
243 : : static int
244 : 0 : intel_ntb_mw_set_trans(const struct rte_rawdev *dev, int mw_idx,
245 : : uint64_t addr, uint64_t size)
246 : : {
247 : 0 : struct ntb_hw *hw = dev->dev_private;
248 : : void *xlat_addr, *limit_addr;
249 : : uint64_t xlat_off, limit_off;
250 : : uint64_t base, limit;
251 : : uint8_t bar;
252 : :
253 [ # # ]: 0 : if (hw == NULL) {
254 : 0 : NTB_LOG(ERR, "Invalid device.");
255 : 0 : return -EINVAL;
256 : : }
257 : :
258 [ # # # # ]: 0 : if (mw_idx < 0 || mw_idx >= hw->mw_cnt) {
259 : 0 : NTB_LOG(ERR, "Invalid memory window index (0 - %u).",
260 : : hw->mw_cnt - 1);
261 : 0 : return -EINVAL;
262 : : }
263 : :
264 : 0 : bar = intel_ntb_bar[mw_idx];
265 : :
266 : 0 : xlat_off = XEON_IMBAR1XBASE_OFFSET + mw_idx * XEON_BAR_INTERVAL_OFFSET;
267 : 0 : limit_off = XEON_IMBAR1XLMT_OFFSET + mw_idx * XEON_BAR_INTERVAL_OFFSET;
268 : 0 : xlat_addr = hw->hw_addr + xlat_off;
269 : 0 : limit_addr = hw->hw_addr + limit_off;
270 : :
271 : : /* Limit reg val should be EMBAR base address plus MW size. */
272 : : base = addr;
273 : 0 : limit = hw->pci_dev->mem_resource[bar].phys_addr + size;
274 : : rte_write64(base, xlat_addr);
275 : : rte_write64(limit, limit_addr);
276 : :
277 : : if (is_gen3_ntb(hw)) {
278 : : /* Setup the external point so that remote can access. */
279 : 0 : xlat_off = XEON_EMBAR1_OFFSET + 8 * mw_idx;
280 : 0 : xlat_addr = hw->hw_addr + xlat_off;
281 : 0 : limit_off = XEON_EMBAR1XLMT_OFFSET +
282 : : mw_idx * XEON_BAR_INTERVAL_OFFSET;
283 : 0 : limit_addr = hw->hw_addr + limit_off;
284 : : base = rte_read64(xlat_addr);
285 : 0 : base &= ~0xf;
286 : 0 : limit = base + size;
287 : : rte_write64(limit, limit_addr);
288 : : } else if (is_gen4_ntb(hw)) {
289 : : /* Set translate base address index register */
290 : 0 : xlat_off = XEON_GEN4_IM1XBASEIDX_OFFSET +
291 : : mw_idx * XEON_GEN4_XBASEIDX_INTERVAL;
292 [ # # ]: 0 : xlat_addr = hw->hw_addr + xlat_off;
293 : 0 : rte_write16(rte_log2_u64(size), xlat_addr);
294 : : } else {
295 : 0 : NTB_LOG(ERR, "Cannot set translation of memory windows for unsupported device.");
296 : : rte_write64(base, limit_addr);
297 : : rte_write64(0, xlat_addr);
298 : 0 : return -ENOTSUP;
299 : : }
300 : :
301 : : return 0;
302 : : }
303 : :
304 : : static void *
305 : 0 : intel_ntb_ioremap(const struct rte_rawdev *dev, uint64_t addr)
306 : : {
307 : 0 : struct ntb_hw *hw = dev->dev_private;
308 : : void *mapped = NULL;
309 : : void *base;
310 : : int i;
311 : :
312 [ # # ]: 0 : for (i = 0; i < hw->peer_used_mws; i++) {
313 [ # # ]: 0 : if (addr >= hw->peer_mw_base[i] &&
314 [ # # ]: 0 : addr <= hw->peer_mw_base[i] + hw->mw_size[i]) {
315 : 0 : base = intel_ntb_get_peer_mw_addr(dev, i);
316 : 0 : mapped = (void *)(size_t)(addr - hw->peer_mw_base[i] +
317 : 0 : (size_t)base);
318 : 0 : break;
319 : : }
320 : : }
321 : :
322 : 0 : return mapped;
323 : : }
324 : :
325 : : static int
326 : 0 : intel_ntb_get_link_status(const struct rte_rawdev *dev)
327 : : {
328 : 0 : struct ntb_hw *hw = dev->dev_private;
329 : : uint16_t reg_val, reg_off;
330 : : int ret;
331 : :
332 [ # # ]: 0 : if (hw == NULL) {
333 : 0 : NTB_LOG(ERR, "Invalid device.");
334 : 0 : return -EINVAL;
335 : : }
336 : :
337 : : if (is_gen3_ntb(hw)) {
338 : : reg_off = XEON_GEN3_LINK_STATUS_OFFSET;
339 : 0 : ret = rte_pci_read_config(hw->pci_dev, ®_val,
340 : : sizeof(reg_val), reg_off);
341 [ # # ]: 0 : if (ret < 0) {
342 : 0 : NTB_LOG(ERR, "Unable to get link status.");
343 : 0 : return -EIO;
344 : : }
345 : : } else if (is_gen4_ntb(hw)) {
346 : : reg_off = XEON_GEN4_LINK_STATUS_OFFSET;
347 : 0 : reg_val = rte_read16(hw->hw_addr + reg_off);
348 : : } else {
349 : 0 : NTB_LOG(ERR, "Cannot get link status for unsupported device.");
350 : 0 : return -ENOTSUP;
351 : : }
352 : :
353 : 0 : hw->link_status = NTB_LNK_STA_ACTIVE(reg_val);
354 : :
355 [ # # ]: 0 : if (hw->link_status) {
356 : 0 : hw->link_speed = NTB_LNK_STA_SPEED(reg_val);
357 : 0 : hw->link_width = NTB_LNK_STA_WIDTH(reg_val);
358 : : } else {
359 : 0 : hw->link_speed = NTB_SPEED_NONE;
360 : 0 : hw->link_width = NTB_WIDTH_NONE;
361 : : }
362 : :
363 : : return 0;
364 : : }
365 : :
366 : : static int
367 : : intel_ntb_gen3_set_link(const struct ntb_hw *hw, bool up)
368 : : {
369 : : uint32_t ntb_ctrl, reg_off;
370 : : void *reg_addr;
371 : :
372 : : reg_off = XEON_NTBCNTL_OFFSET;
373 : 0 : reg_addr = hw->hw_addr + reg_off;
374 : : ntb_ctrl = rte_read32(reg_addr);
375 : :
376 [ # # ]: 0 : if (up) {
377 : 0 : ntb_ctrl &= ~(NTB_CTL_DISABLE | NTB_CTL_CFG_LOCK);
378 : : ntb_ctrl |= NTB_CTL_P2S_BAR2_SNOOP | NTB_CTL_S2P_BAR2_SNOOP;
379 : 0 : ntb_ctrl |= NTB_CTL_P2S_BAR4_SNOOP | NTB_CTL_S2P_BAR4_SNOOP;
380 : : } else {
381 : : ntb_ctrl &= ~(NTB_CTL_P2S_BAR2_SNOOP | NTB_CTL_S2P_BAR2_SNOOP);
382 : 0 : ntb_ctrl &= ~(NTB_CTL_P2S_BAR4_SNOOP | NTB_CTL_S2P_BAR4_SNOOP);
383 : 0 : ntb_ctrl |= NTB_CTL_DISABLE | NTB_CTL_CFG_LOCK;
384 : : }
385 : :
386 : : rte_write32(ntb_ctrl, reg_addr);
387 : :
388 : : return 0;
389 : : }
390 : :
391 : : static int
392 : 0 : intel_ntb_gen4_set_link(const struct ntb_hw *hw, bool up)
393 : : {
394 : : uint32_t ntb_ctrl, ppd0;
395 : : uint16_t link_ctrl;
396 : : void *reg_addr;
397 : :
398 [ # # ]: 0 : if (up) {
399 : 0 : reg_addr = hw->hw_addr + XEON_NTBCNTL_OFFSET;
400 : : ntb_ctrl = NTB_CTL_P2S_BAR2_SNOOP | NTB_CTL_S2P_BAR2_SNOOP;
401 : : ntb_ctrl |= NTB_CTL_P2S_BAR4_SNOOP | NTB_CTL_S2P_BAR4_SNOOP;
402 : : rte_write32(ntb_ctrl, reg_addr);
403 : :
404 : 0 : reg_addr = hw->hw_addr + XEON_GEN4_LINK_CTRL_OFFSET;
405 : : link_ctrl = rte_read16(reg_addr);
406 : 0 : link_ctrl &= ~XEON_GEN4_LINK_CTRL_LINK_DIS;
407 : : rte_write16(link_ctrl, reg_addr);
408 : :
409 : : /* start link training */
410 : 0 : reg_addr = hw->hw_addr + XEON_GEN4_PPD0_OFFSET;
411 : : ppd0 = rte_read32(reg_addr);
412 : 0 : ppd0 |= XEON_GEN4_PPD_LINKTRN;
413 : : rte_write32(ppd0, reg_addr);
414 : :
415 : : /* make sure link training has started */
416 : : ppd0 = rte_read32(reg_addr);
417 [ # # ]: 0 : if (!(ppd0 & XEON_GEN4_PPD_LINKTRN)) {
418 : 0 : NTB_LOG(ERR, "Link is not training.");
419 : 0 : return -EINVAL;
420 : : }
421 : : } else {
422 : 0 : reg_addr = hw->hw_addr + XEON_NTBCNTL_OFFSET;
423 : : ntb_ctrl = rte_read32(reg_addr);
424 : : ntb_ctrl &= ~(NTB_CTL_P2S_BAR2_SNOOP | NTB_CTL_S2P_BAR2_SNOOP);
425 : 0 : ntb_ctrl &= ~(NTB_CTL_P2S_BAR4_SNOOP | NTB_CTL_S2P_BAR4_SNOOP);
426 : : rte_write32(ntb_ctrl, reg_addr);
427 : :
428 : 0 : reg_addr = hw->hw_addr + XEON_GEN4_LINK_CTRL_OFFSET;
429 : : link_ctrl = rte_read16(reg_addr);
430 : 0 : link_ctrl |= XEON_GEN4_LINK_CTRL_LINK_DIS;
431 : : rte_write16(link_ctrl, reg_addr);
432 : : }
433 : :
434 : : return 0;
435 : : }
436 : :
437 : : static int
438 : 0 : intel_ntb_set_link(const struct rte_rawdev *dev, bool up)
439 : : {
440 [ # # ]: 0 : struct ntb_hw *hw = dev->dev_private;
441 : : int ret = 0;
442 : :
443 : : if (is_gen3_ntb(hw))
444 : : ret = intel_ntb_gen3_set_link(hw, up);
445 : : else if (is_gen4_ntb(hw))
446 : 0 : ret = intel_ntb_gen4_set_link(hw, up);
447 : : else {
448 : 0 : NTB_LOG(ERR, "Cannot set link for unsupported device.");
449 : : ret = -ENOTSUP;
450 : : }
451 : :
452 : 0 : return ret;
453 : : }
454 : :
455 : : static uint32_t
456 : 0 : intel_ntb_spad_read(const struct rte_rawdev *dev, int spad, bool peer)
457 : : {
458 : 0 : struct ntb_hw *hw = dev->dev_private;
459 : : uint32_t spad_v, reg_off;
460 : : void *reg_addr;
461 : :
462 [ # # # # ]: 0 : if (spad < 0 || spad >= hw->spad_cnt) {
463 : 0 : NTB_LOG(ERR, "Invalid spad reg index.");
464 : 0 : return 0;
465 : : }
466 : :
467 : : /* When peer is true, read peer spad reg */
468 : : if (is_gen3_ntb(hw))
469 [ # # ]: 0 : reg_off = peer ? XEON_GEN3_B2B_SPAD_OFFSET :
470 : : XEON_IM_SPAD_OFFSET;
471 : : else if (is_gen4_ntb(hw))
472 [ # # ]: 0 : reg_off = peer ? XEON_GEN4_B2B_SPAD_OFFSET :
473 : : XEON_IM_SPAD_OFFSET;
474 : : else {
475 : 0 : NTB_LOG(ERR, "Cannot read spad for unsupported device.");
476 : 0 : return -ENOTSUP;
477 : : }
478 : 0 : reg_addr = hw->hw_addr + reg_off + (spad << 2);
479 : : spad_v = rte_read32(reg_addr);
480 : :
481 : 0 : return spad_v;
482 : : }
483 : :
484 : : static int
485 : 0 : intel_ntb_spad_write(const struct rte_rawdev *dev, int spad,
486 : : bool peer, uint32_t spad_v)
487 : : {
488 : 0 : struct ntb_hw *hw = dev->dev_private;
489 : : uint32_t reg_off;
490 : : void *reg_addr;
491 : :
492 [ # # # # ]: 0 : if (spad < 0 || spad >= hw->spad_cnt) {
493 : 0 : NTB_LOG(ERR, "Invalid spad reg index.");
494 : 0 : return -EINVAL;
495 : : }
496 : :
497 : : /* When peer is true, write peer spad reg */
498 : : if (is_gen3_ntb(hw))
499 [ # # ]: 0 : reg_off = peer ? XEON_GEN3_B2B_SPAD_OFFSET :
500 : : XEON_IM_SPAD_OFFSET;
501 : : else if (is_gen4_ntb(hw))
502 [ # # ]: 0 : reg_off = peer ? XEON_GEN4_B2B_SPAD_OFFSET :
503 : : XEON_IM_SPAD_OFFSET;
504 : : else {
505 : 0 : NTB_LOG(ERR, "Cannot write spad for unsupported device.");
506 : 0 : return -ENOTSUP;
507 : : }
508 : 0 : reg_addr = hw->hw_addr + reg_off + (spad << 2);
509 : :
510 : : rte_write32(spad_v, reg_addr);
511 : :
512 : 0 : return 0;
513 : : }
514 : :
515 : : static uint64_t
516 : 0 : intel_ntb_db_read(const struct rte_rawdev *dev)
517 : : {
518 : 0 : struct ntb_hw *hw = dev->dev_private;
519 : : uint64_t db_off, db_bits;
520 : : void *db_addr;
521 : :
522 : : db_off = XEON_IM_INT_STATUS_OFFSET;
523 : 0 : db_addr = hw->hw_addr + db_off;
524 : :
525 : : db_bits = rte_read64(db_addr);
526 : :
527 : 0 : return db_bits;
528 : : }
529 : :
530 : : static int
531 : 0 : intel_ntb_db_clear(const struct rte_rawdev *dev, uint64_t db_bits)
532 : : {
533 : 0 : struct ntb_hw *hw = dev->dev_private;
534 : : uint64_t db_off;
535 : : void *db_addr;
536 : :
537 : : db_off = XEON_IM_INT_STATUS_OFFSET;
538 [ # # ]: 0 : db_addr = hw->hw_addr + db_off;
539 : :
540 : : if (is_gen4_ntb(hw))
541 : : rte_write16(XEON_GEN4_SLOTSTS_DLLSCS,
542 : : hw->hw_addr + XEON_GEN4_SLOTSTS);
543 : : rte_write64(db_bits, db_addr);
544 : :
545 : 0 : return 0;
546 : : }
547 : :
548 : : static int
549 : 0 : intel_ntb_db_set_mask(const struct rte_rawdev *dev, uint64_t db_mask)
550 : : {
551 : 0 : struct ntb_hw *hw = dev->dev_private;
552 : : uint64_t db_m_off;
553 : : void *db_m_addr;
554 : :
555 : : db_m_off = XEON_IM_INT_DISABLE_OFFSET;
556 : 0 : db_m_addr = hw->hw_addr + db_m_off;
557 : :
558 : 0 : db_mask |= hw->db_mask;
559 : :
560 : : rte_write64(db_mask, db_m_addr);
561 : :
562 : 0 : hw->db_mask = db_mask;
563 : :
564 : 0 : return 0;
565 : : }
566 : :
567 : : static int
568 : 0 : intel_ntb_peer_db_set(const struct rte_rawdev *dev, uint8_t db_idx)
569 : : {
570 : 0 : struct ntb_hw *hw = dev->dev_private;
571 : : uint32_t db_off;
572 : : void *db_addr;
573 : :
574 [ # # ]: 0 : if (((uint64_t)1 << db_idx) & ~hw->db_valid_mask) {
575 : 0 : NTB_LOG(ERR, "Invalid doorbell.");
576 : 0 : return -EINVAL;
577 : : }
578 : :
579 : 0 : db_off = XEON_IM_DOORBELL_OFFSET + db_idx * 4;
580 : 0 : db_addr = hw->hw_addr + db_off;
581 : :
582 : : rte_write32(1, db_addr);
583 : :
584 : 0 : return 0;
585 : : }
586 : :
587 : : static int
588 : 0 : intel_ntb_vector_bind(const struct rte_rawdev *dev, uint8_t intr, uint8_t msix)
589 : : {
590 : 0 : struct ntb_hw *hw = dev->dev_private;
591 : : uint8_t reg_off;
592 : : void *reg_addr;
593 : :
594 [ # # ]: 0 : if (intr >= hw->db_cnt) {
595 : 0 : NTB_LOG(ERR, "Invalid intr source.");
596 : 0 : return -EINVAL;
597 : : }
598 : :
599 : : /* Bind intr source to msix vector */
600 : : if (is_gen3_ntb(hw))
601 : : reg_off = XEON_GEN3_INTVEC_OFFSET;
602 : : else if (is_gen4_ntb(hw))
603 : : reg_off = XEON_GEN4_INTVEC_OFFSET;
604 : : else {
605 : 0 : NTB_LOG(ERR, "Cannot bind vectors for unsupported device.");
606 : 0 : return -ENOTSUP;
607 : : }
608 : 0 : reg_addr = hw->hw_addr + reg_off + intr;
609 : :
610 : : rte_write8(msix, reg_addr);
611 : :
612 : 0 : return 0;
613 : : }
614 : :
615 : : /* operations for primary side of local ntb */
616 : : const struct ntb_dev_ops intel_ntb_ops = {
617 : : .ntb_dev_init = intel_ntb_dev_init,
618 : : .get_peer_mw_addr = intel_ntb_get_peer_mw_addr,
619 : : .mw_set_trans = intel_ntb_mw_set_trans,
620 : : .ioremap = intel_ntb_ioremap,
621 : : .get_link_status = intel_ntb_get_link_status,
622 : : .set_link = intel_ntb_set_link,
623 : : .spad_read = intel_ntb_spad_read,
624 : : .spad_write = intel_ntb_spad_write,
625 : : .db_read = intel_ntb_db_read,
626 : : .db_clear = intel_ntb_db_clear,
627 : : .db_set_mask = intel_ntb_db_set_mask,
628 : : .peer_db_set = intel_ntb_peer_db_set,
629 : : .vector_bind = intel_ntb_vector_bind,
630 : : };
|