event/dlb2: add eventdev probe
[dpdk.git] / drivers / event / dlb2 / pf / dlb2_main.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2020 Intel Corporation
3  */
4
5 #include <stdint.h>
6 #include <stdbool.h>
7 #include <stdio.h>
8 #include <errno.h>
9 #include <assert.h>
10 #include <unistd.h>
11 #include <string.h>
12
13 #include <rte_malloc.h>
14 #include <rte_errno.h>
15
16 #include "base/dlb2_resource.h"
17 #include "base/dlb2_osdep.h"
18 #include "base/dlb2_regs.h"
19 #include "dlb2_main.h"
20 #include "../dlb2_user.h"
21 #include "../dlb2_priv.h"
22 #include "../dlb2_inline_fns.h"
23
24 #define PF_ID_ZERO 0    /* PF ONLY! */
25 #define NO_OWNER_VF 0   /* PF ONLY! */
26 #define NOT_VF_REQ false /* PF ONLY! */
27
28 #define DLB2_PCI_CFG_SPACE_SIZE 256
29 #define DLB2_PCI_CAP_POINTER 0x34
30 #define DLB2_PCI_CAP_NEXT(hdr) (((hdr) >> 8) & 0xFC)
31 #define DLB2_PCI_CAP_ID(hdr) ((hdr) & 0xFF)
32 #define DLB2_PCI_EXT_CAP_NEXT(hdr) (((hdr) >> 20) & 0xFFC)
33 #define DLB2_PCI_EXT_CAP_ID(hdr) ((hdr) & 0xFFFF)
34 #define DLB2_PCI_EXT_CAP_ID_ERR 1
35 #define DLB2_PCI_ERR_UNCOR_MASK 8
36 #define DLB2_PCI_ERR_UNC_UNSUP  0x00100000
37
38 #define DLB2_PCI_EXP_DEVCTL 8
39 #define DLB2_PCI_LNKCTL 16
40 #define DLB2_PCI_SLTCTL 24
41 #define DLB2_PCI_RTCTL 28
42 #define DLB2_PCI_EXP_DEVCTL2 40
43 #define DLB2_PCI_LNKCTL2 48
44 #define DLB2_PCI_SLTCTL2 56
45 #define DLB2_PCI_CMD 4
46 #define DLB2_PCI_X_CMD 2
47 #define DLB2_PCI_EXP_DEVSTA 10
48 #define DLB2_PCI_EXP_DEVSTA_TRPND 0x20
49 #define DLB2_PCI_EXP_DEVCTL_BCR_FLR 0x8000
50
51 #define DLB2_PCI_CAP_ID_EXP       0x10
52 #define DLB2_PCI_CAP_ID_MSIX      0x11
53 #define DLB2_PCI_EXT_CAP_ID_PAS   0x1B
54 #define DLB2_PCI_EXT_CAP_ID_PRI   0x13
55 #define DLB2_PCI_EXT_CAP_ID_ACS   0xD
56
57 #define DLB2_PCI_PRI_CTRL_ENABLE         0x1
58 #define DLB2_PCI_PRI_ALLOC_REQ           0xC
59 #define DLB2_PCI_PRI_CTRL                0x4
60 #define DLB2_PCI_MSIX_FLAGS              0x2
61 #define DLB2_PCI_MSIX_FLAGS_ENABLE       0x8000
62 #define DLB2_PCI_MSIX_FLAGS_MASKALL      0x4000
63 #define DLB2_PCI_ERR_ROOT_STATUS         0x30
64 #define DLB2_PCI_ERR_COR_STATUS          0x10
65 #define DLB2_PCI_ERR_UNCOR_STATUS        0x4
66 #define DLB2_PCI_COMMAND_INTX_DISABLE    0x400
67 #define DLB2_PCI_ACS_CAP                 0x4
68 #define DLB2_PCI_ACS_CTRL                0x6
69 #define DLB2_PCI_ACS_SV                  0x1
70 #define DLB2_PCI_ACS_RR                  0x4
71 #define DLB2_PCI_ACS_CR                  0x8
72 #define DLB2_PCI_ACS_UF                  0x10
73 #define DLB2_PCI_ACS_EC                  0x20
74
75 /* Stubs: Allow building partial probe patch */
76 void dlb2_resource_free(struct dlb2_hw *hw)
77 {
78         RTE_SET_USED(hw);
79 }
80
81 int dlb2_resource_init(struct dlb2_hw *hw)
82 {
83         int ret = 0;
84         RTE_SET_USED(hw);
85
86         return ret;
87 }
88
89 void dlb2_clr_pmcsr_disable(struct dlb2_hw *hw)
90 {
91         RTE_SET_USED(hw);
92 }
93
94 /* End stubs */
95
96 static int
97 dlb2_pci_find_ext_capability(struct rte_pci_device *pdev, uint32_t id)
98 {
99         uint32_t hdr;
100         size_t sz;
101         int pos;
102
103         pos = DLB2_PCI_CFG_SPACE_SIZE;
104         sz = sizeof(hdr);
105
106         while (pos > 0xFF) {
107                 if (rte_pci_read_config(pdev, &hdr, sz, pos) != (int)sz)
108                         return -1;
109
110                 if (DLB2_PCI_EXT_CAP_ID(hdr) == id)
111                         return pos;
112
113                 pos = DLB2_PCI_EXT_CAP_NEXT(hdr);
114         }
115
116         return -1;
117 }
118
119 static int dlb2_pci_find_capability(struct rte_pci_device *pdev, uint32_t id)
120 {
121         uint8_t pos;
122         int ret;
123         uint16_t hdr;
124
125         ret = rte_pci_read_config(pdev, &pos, 1, DLB2_PCI_CAP_POINTER);
126         pos &= 0xFC;
127
128         if (ret != 1)
129                 return -1;
130
131         while (pos > 0x3F) {
132                 ret = rte_pci_read_config(pdev, &hdr, 2, pos);
133                 if (ret != 2)
134                         return -1;
135
136                 if (DLB2_PCI_CAP_ID(hdr) == id)
137                         return pos;
138
139                 if (DLB2_PCI_CAP_ID(hdr) == 0xFF)
140                         return -1;
141
142                 pos = DLB2_PCI_CAP_NEXT(hdr);
143         }
144
145         return -1;
146 }
147
148 static int
149 dlb2_pf_init_driver_state(struct dlb2_dev *dlb2_dev)
150 {
151         rte_spinlock_init(&dlb2_dev->resource_mutex);
152         rte_spinlock_init(&dlb2_dev->measurement_lock);
153
154         return 0;
155 }
156
157 static void dlb2_pf_enable_pm(struct dlb2_dev *dlb2_dev)
158 {
159         dlb2_clr_pmcsr_disable(&dlb2_dev->hw);
160 }
161
162 #define DLB2_READY_RETRY_LIMIT 1000
163 static int dlb2_pf_wait_for_device_ready(struct dlb2_dev *dlb2_dev)
164 {
165         u32 retries = 0;
166
167         /* Allow at least 1s for the device to become active after power-on */
168         for (retries = 0; retries < DLB2_READY_RETRY_LIMIT; retries++) {
169                 union dlb2_cfg_mstr_cfg_diagnostic_idle_status idle;
170                 union dlb2_cfg_mstr_cfg_pm_status pm_st;
171                 u32 addr;
172
173                 addr = DLB2_CFG_MSTR_CFG_PM_STATUS;
174                 pm_st.val = DLB2_CSR_RD(&dlb2_dev->hw, addr);
175                 addr = DLB2_CFG_MSTR_CFG_DIAGNOSTIC_IDLE_STATUS;
176                 idle.val = DLB2_CSR_RD(&dlb2_dev->hw, addr);
177                 if (pm_st.field.pmsm == 1 && idle.field.dlb_func_idle == 1)
178                         break;
179
180                 rte_delay_ms(1);
181         };
182
183         if (retries == DLB2_READY_RETRY_LIMIT) {
184                 DLB2_LOG_ERR("[%s()] wait for device ready timed out\n",
185                        __func__);
186                 return -1;
187         }
188
189         return 0;
190 }
191
192 struct dlb2_dev *
193 dlb2_probe(struct rte_pci_device *pdev)
194 {
195         struct dlb2_dev *dlb2_dev;
196         int ret = 0;
197
198         DLB2_INFO(dlb2_dev, "probe\n");
199
200         dlb2_dev = rte_malloc("DLB2_PF", sizeof(struct dlb2_dev),
201                               RTE_CACHE_LINE_SIZE);
202
203         if (dlb2_dev == NULL) {
204                 ret = -ENOMEM;
205                 goto dlb2_dev_malloc_fail;
206         }
207
208         /* PCI Bus driver has already mapped bar space into process.
209          * Save off our IO register and FUNC addresses.
210          */
211
212         /* BAR 0 */
213         if (pdev->mem_resource[0].addr == NULL) {
214                 DLB2_ERR(dlb2_dev, "probe: BAR 0 addr (csr_kva) is NULL\n");
215                 ret = -EINVAL;
216                 goto pci_mmap_bad_addr;
217         }
218         dlb2_dev->hw.func_kva = (void *)(uintptr_t)pdev->mem_resource[0].addr;
219         dlb2_dev->hw.func_phys_addr = pdev->mem_resource[0].phys_addr;
220
221         DLB2_INFO(dlb2_dev, "DLB2 FUNC VA=%p, PA=%p, len=%p\n",
222                   (void *)dlb2_dev->hw.func_kva,
223                   (void *)dlb2_dev->hw.func_phys_addr,
224                   (void *)(pdev->mem_resource[0].len));
225
226         /* BAR 2 */
227         if (pdev->mem_resource[2].addr == NULL) {
228                 DLB2_ERR(dlb2_dev, "probe: BAR 2 addr (func_kva) is NULL\n");
229                 ret = -EINVAL;
230                 goto pci_mmap_bad_addr;
231         }
232         dlb2_dev->hw.csr_kva = (void *)(uintptr_t)pdev->mem_resource[2].addr;
233         dlb2_dev->hw.csr_phys_addr = pdev->mem_resource[2].phys_addr;
234
235         DLB2_INFO(dlb2_dev, "DLB2 CSR VA=%p, PA=%p, len=%p\n",
236                   (void *)dlb2_dev->hw.csr_kva,
237                   (void *)dlb2_dev->hw.csr_phys_addr,
238                   (void *)(pdev->mem_resource[2].len));
239
240         dlb2_dev->pdev = pdev;
241
242         /* PM enable must be done before any other MMIO accesses, and this
243          * setting is persistent across device reset.
244          */
245         dlb2_pf_enable_pm(dlb2_dev);
246
247         ret = dlb2_pf_wait_for_device_ready(dlb2_dev);
248         if (ret)
249                 goto wait_for_device_ready_fail;
250
251         ret = dlb2_pf_reset(dlb2_dev);
252         if (ret)
253                 goto dlb2_reset_fail;
254
255         ret = dlb2_pf_init_driver_state(dlb2_dev);
256         if (ret)
257                 goto init_driver_state_fail;
258
259         ret = dlb2_resource_init(&dlb2_dev->hw);
260         if (ret)
261                 goto resource_init_fail;
262
263         return dlb2_dev;
264
265 resource_init_fail:
266         dlb2_resource_free(&dlb2_dev->hw);
267 init_driver_state_fail:
268 dlb2_reset_fail:
269 pci_mmap_bad_addr:
270 wait_for_device_ready_fail:
271         rte_free(dlb2_dev);
272 dlb2_dev_malloc_fail:
273         rte_errno = ret;
274         return NULL;
275 }
276
277 int
278 dlb2_pf_reset(struct dlb2_dev *dlb2_dev)
279 {
280         int ret = 0;
281         int i = 0;
282         uint32_t dword[16];
283         uint16_t cmd;
284         off_t off;
285
286         uint16_t dev_ctl_word;
287         uint16_t dev_ctl2_word;
288         uint16_t lnk_word;
289         uint16_t lnk_word2;
290         uint16_t slt_word;
291         uint16_t slt_word2;
292         uint16_t rt_ctl_word;
293         uint32_t pri_reqs_dword;
294         uint16_t pri_ctrl_word;
295
296         int pcie_cap_offset;
297         int pri_cap_offset;
298         int msix_cap_offset;
299         int err_cap_offset;
300         int acs_cap_offset;
301         int wait_count;
302
303         uint16_t devsta_busy_word;
304         uint16_t devctl_word;
305
306         struct rte_pci_device *pdev = dlb2_dev->pdev;
307
308         /* Save PCI config state */
309
310         for (i = 0; i < 16; i++) {
311                 if (rte_pci_read_config(pdev, &dword[i], 4, i * 4) != 4)
312                         return ret;
313         }
314
315         pcie_cap_offset = dlb2_pci_find_capability(pdev, DLB2_PCI_CAP_ID_EXP);
316
317         if (pcie_cap_offset < 0) {
318                 DLB2_LOG_ERR("[%s()] failed to find the pcie capability\n",
319                        __func__);
320                 return pcie_cap_offset;
321         }
322
323         off = pcie_cap_offset + DLB2_PCI_EXP_DEVCTL;
324         if (rte_pci_read_config(pdev, &dev_ctl_word, 2, off) != 2)
325                 dev_ctl_word = 0;
326
327         off = pcie_cap_offset + DLB2_PCI_LNKCTL;
328         if (rte_pci_read_config(pdev, &lnk_word, 2, off) != 2)
329                 lnk_word = 0;
330
331         off = pcie_cap_offset + DLB2_PCI_SLTCTL;
332         if (rte_pci_read_config(pdev, &slt_word, 2, off) != 2)
333                 slt_word = 0;
334
335         off = pcie_cap_offset + DLB2_PCI_RTCTL;
336         if (rte_pci_read_config(pdev, &rt_ctl_word, 2, off) != 2)
337                 rt_ctl_word = 0;
338
339         off = pcie_cap_offset + DLB2_PCI_EXP_DEVCTL2;
340         if (rte_pci_read_config(pdev, &dev_ctl2_word, 2, off) != 2)
341                 dev_ctl2_word = 0;
342
343         off = pcie_cap_offset + DLB2_PCI_LNKCTL2;
344         if (rte_pci_read_config(pdev, &lnk_word2, 2, off) != 2)
345                 lnk_word2 = 0;
346
347         off = pcie_cap_offset + DLB2_PCI_SLTCTL2;
348         if (rte_pci_read_config(pdev, &slt_word2, 2, off) != 2)
349                 slt_word2 = 0;
350
351         off = DLB2_PCI_EXT_CAP_ID_PRI;
352         pri_cap_offset = dlb2_pci_find_ext_capability(pdev, off);
353
354         if (pri_cap_offset >= 0) {
355                 off = pri_cap_offset + DLB2_PCI_PRI_ALLOC_REQ;
356                 if (rte_pci_read_config(pdev, &pri_reqs_dword, 4, off) != 4)
357                         pri_reqs_dword = 0;
358         }
359
360         /* clear the PCI command register before issuing the FLR */
361
362         off = DLB2_PCI_CMD;
363         cmd = 0;
364         if (rte_pci_write_config(pdev, &cmd, 2, off) != 2) {
365                 DLB2_LOG_ERR("[%s()] failed to write the pci command\n",
366                        __func__);
367                 return ret;
368         }
369
370         /* issue the FLR */
371         for (wait_count = 0; wait_count < 4; wait_count++) {
372                 int sleep_time;
373
374                 off = pcie_cap_offset + DLB2_PCI_EXP_DEVSTA;
375                 ret = rte_pci_read_config(pdev, &devsta_busy_word, 2, off);
376                 if (ret != 2) {
377                         DLB2_LOG_ERR("[%s()] failed to read the pci device status\n",
378                                __func__);
379                         return ret;
380                 }
381
382                 if (!(devsta_busy_word & DLB2_PCI_EXP_DEVSTA_TRPND))
383                         break;
384
385                 sleep_time = (1 << (wait_count)) * 100;
386                 rte_delay_ms(sleep_time);
387         }
388
389         if (wait_count == 4) {
390                 DLB2_LOG_ERR("[%s()] wait for pci pending transactions timed out\n",
391                        __func__);
392                 return -1;
393         }
394
395         off = pcie_cap_offset + DLB2_PCI_EXP_DEVCTL;
396         ret = rte_pci_read_config(pdev, &devctl_word, 2, off);
397         if (ret != 2) {
398                 DLB2_LOG_ERR("[%s()] failed to read the pcie device control\n",
399                        __func__);
400                 return ret;
401         }
402
403         devctl_word |= DLB2_PCI_EXP_DEVCTL_BCR_FLR;
404
405         ret = rte_pci_write_config(pdev, &devctl_word, 2, off);
406         if (ret != 2) {
407                 DLB2_LOG_ERR("[%s()] failed to write the pcie device control\n",
408                        __func__);
409                 return ret;
410         }
411
412         rte_delay_ms(100);
413
414         /* Restore PCI config state */
415
416         if (pcie_cap_offset >= 0) {
417                 off = pcie_cap_offset + DLB2_PCI_EXP_DEVCTL;
418                 ret = rte_pci_write_config(pdev, &dev_ctl_word, 2, off);
419                 if (ret != 2) {
420                         DLB2_LOG_ERR("[%s()] failed to write the pcie device control at offset %d\n",
421                                 __func__, (int)off);
422                         return ret;
423                 }
424
425                 off = pcie_cap_offset + DLB2_PCI_LNKCTL;
426                 ret = rte_pci_write_config(pdev, &lnk_word, 2, off);
427                 if (ret != 2) {
428                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
429                                 __func__, (int)off);
430                         return ret;
431                 }
432
433                 off = pcie_cap_offset + DLB2_PCI_SLTCTL;
434                 ret = rte_pci_write_config(pdev, &slt_word, 2, off);
435                 if (ret != 2) {
436                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
437                                 __func__, (int)off);
438                         return ret;
439                 }
440
441                 off = pcie_cap_offset + DLB2_PCI_RTCTL;
442                 ret = rte_pci_write_config(pdev, &rt_ctl_word, 2, off);
443                 if (ret != 2) {
444                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
445                                 __func__, (int)off);
446                         return ret;
447                 }
448
449                 off = pcie_cap_offset + DLB2_PCI_EXP_DEVCTL2;
450                 ret = rte_pci_write_config(pdev, &dev_ctl2_word, 2, off);
451                 if (ret != 2) {
452                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
453                                 __func__, (int)off);
454                         return ret;
455                 }
456
457                 off = pcie_cap_offset + DLB2_PCI_LNKCTL2;
458                 ret = rte_pci_write_config(pdev, &lnk_word2, 2, off);
459                 if (ret != 2) {
460                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
461                                 __func__, (int)off);
462                         return ret;
463                 }
464
465                 off = pcie_cap_offset + DLB2_PCI_SLTCTL2;
466                 ret = rte_pci_write_config(pdev, &slt_word2, 2, off);
467                 if (ret != 2) {
468                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
469                                 __func__, (int)off);
470                         return ret;
471                 }
472         }
473
474         if (pri_cap_offset >= 0) {
475                 pri_ctrl_word = DLB2_PCI_PRI_CTRL_ENABLE;
476
477                 off = pri_cap_offset + DLB2_PCI_PRI_ALLOC_REQ;
478                 ret = rte_pci_write_config(pdev, &pri_reqs_dword, 4, off);
479                 if (ret != 4) {
480                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
481                                 __func__, (int)off);
482                         return ret;
483                 }
484
485                 off = pri_cap_offset + DLB2_PCI_PRI_CTRL;
486                 ret = rte_pci_write_config(pdev, &pri_ctrl_word, 2, off);
487                 if (ret != 2) {
488                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
489                                 __func__, (int)off);
490                         return ret;
491                 }
492         }
493
494         off = DLB2_PCI_EXT_CAP_ID_ERR;
495         err_cap_offset = dlb2_pci_find_ext_capability(pdev, off);
496
497         if (err_cap_offset >= 0) {
498                 uint32_t tmp;
499
500                 off = err_cap_offset + DLB2_PCI_ERR_ROOT_STATUS;
501                 if (rte_pci_read_config(pdev, &tmp, 4, off) != 4)
502                         tmp = 0;
503
504                 ret = rte_pci_write_config(pdev, &tmp, 4, off);
505                 if (ret != 4) {
506                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
507                                 __func__, (int)off);
508                         return ret;
509                 }
510
511                 off = err_cap_offset + DLB2_PCI_ERR_COR_STATUS;
512                 if (rte_pci_read_config(pdev, &tmp, 4, off) != 4)
513                         tmp = 0;
514
515                 ret = rte_pci_write_config(pdev, &tmp, 4, off);
516                 if (ret != 4) {
517                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
518                                 __func__, (int)off);
519                         return ret;
520                 }
521
522                 off = err_cap_offset + DLB2_PCI_ERR_UNCOR_STATUS;
523                 if (rte_pci_read_config(pdev, &tmp, 4, off) != 4)
524                         tmp = 0;
525
526                 ret = rte_pci_write_config(pdev, &tmp, 4, off);
527                 if (ret != 4) {
528                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
529                                 __func__, (int)off);
530                         return ret;
531                 }
532         }
533
534         for (i = 16; i > 0; i--) {
535                 off = (i - 1) * 4;
536                 ret = rte_pci_write_config(pdev, &dword[i - 1], 4, off);
537                 if (ret != 4) {
538                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
539                                 __func__, (int)off);
540                         return ret;
541                 }
542         }
543
544         off = DLB2_PCI_CMD;
545         if (rte_pci_read_config(pdev, &cmd, 2, off) == 2) {
546                 cmd &= ~DLB2_PCI_COMMAND_INTX_DISABLE;
547                 if (rte_pci_write_config(pdev, &cmd, 2, off) != 2) {
548                         DLB2_LOG_ERR("[%s()] failed to write the pci command\n",
549                                __func__);
550                         return ret;
551                 }
552         }
553
554         msix_cap_offset = dlb2_pci_find_capability(pdev,
555                                                    DLB2_PCI_CAP_ID_MSIX);
556         if (msix_cap_offset >= 0) {
557                 off = msix_cap_offset + DLB2_PCI_MSIX_FLAGS;
558                 if (rte_pci_read_config(pdev, &cmd, 2, off) == 2) {
559                         cmd |= DLB2_PCI_MSIX_FLAGS_ENABLE;
560                         cmd |= DLB2_PCI_MSIX_FLAGS_MASKALL;
561                         if (rte_pci_write_config(pdev, &cmd, 2, off) != 2) {
562                                 DLB2_LOG_ERR("[%s()] failed to write msix flags\n",
563                                        __func__);
564                                 return ret;
565                         }
566                 }
567
568                 off = msix_cap_offset + DLB2_PCI_MSIX_FLAGS;
569                 if (rte_pci_read_config(pdev, &cmd, 2, off) == 2) {
570                         cmd &= ~DLB2_PCI_MSIX_FLAGS_MASKALL;
571                         if (rte_pci_write_config(pdev, &cmd, 2, off) != 2) {
572                                 DLB2_LOG_ERR("[%s()] failed to write msix flags\n",
573                                        __func__);
574                                 return ret;
575                         }
576                 }
577         }
578
579         off = DLB2_PCI_EXT_CAP_ID_ACS;
580         acs_cap_offset = dlb2_pci_find_ext_capability(pdev, off);
581
582         if (acs_cap_offset >= 0) {
583                 uint16_t acs_cap, acs_ctrl, acs_mask;
584                 off = acs_cap_offset + DLB2_PCI_ACS_CAP;
585                 if (rte_pci_read_config(pdev, &acs_cap, 2, off) != 2)
586                         acs_cap = 0;
587
588                 off = acs_cap_offset + DLB2_PCI_ACS_CTRL;
589                 if (rte_pci_read_config(pdev, &acs_ctrl, 2, off) != 2)
590                         acs_ctrl = 0;
591
592                 acs_mask = DLB2_PCI_ACS_SV | DLB2_PCI_ACS_RR;
593                 acs_mask |= (DLB2_PCI_ACS_CR | DLB2_PCI_ACS_UF);
594                 acs_ctrl |= (acs_cap & acs_mask);
595
596                 ret = rte_pci_write_config(pdev, &acs_ctrl, 2, off);
597                 if (ret != 2) {
598                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
599                                 __func__, (int)off);
600                         return ret;
601                 }
602
603                 off = acs_cap_offset + DLB2_PCI_ACS_CTRL;
604                 if (rte_pci_read_config(pdev, &acs_ctrl, 2, off) != 2)
605                         acs_ctrl = 0;
606
607                 acs_mask = DLB2_PCI_ACS_RR | DLB2_PCI_ACS_CR;
608                 acs_mask |= DLB2_PCI_ACS_EC;
609                 acs_ctrl &= ~acs_mask;
610
611                 off = acs_cap_offset + DLB2_PCI_ACS_CTRL;
612                 ret = rte_pci_write_config(pdev, &acs_ctrl, 2, off);
613                 if (ret != 2) {
614                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d\n",
615                                 __func__, (int)off);
616                         return ret;
617                 }
618         }
619
620         return 0;
621 }