Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(C) 2021 Marvell. 3 : : */ 4 : : 5 : : #include <fcntl.h> 6 : : #include <sys/stat.h> 7 : : #include <sys/types.h> 8 : : #include <unistd.h> 9 : : 10 : : #include "roc_api.h" 11 : : #include "roc_priv.h" 12 : : 13 : : #define DPI_PF_MBOX_SYSFS_ENTRY "dpi_device_config" 14 : : 15 : : static inline int 16 : 0 : send_msg_to_pf(struct plt_pci_addr *pci_addr, const char *value, int size) 17 : : { 18 : 0 : char buf[255] = {0}; 19 : : int res, fd; 20 : : 21 : 0 : res = snprintf( 22 : : buf, sizeof(buf), "/sys/bus/pci/devices/" PCI_PRI_FMT "/%s", 23 [ # # ]: 0 : pci_addr->domain, pci_addr->bus, DPI_PF_DBDF_DEVICE & 0x7, 24 : : DPI_PF_DBDF_FUNCTION & 0x7, DPI_PF_MBOX_SYSFS_ENTRY); 25 : : 26 [ # # ]: 0 : if ((res < 0) || ((size_t)res > sizeof(buf))) 27 : : return -ERANGE; 28 : : 29 : : fd = open(buf, O_WRONLY); 30 [ # # ]: 0 : if (fd < 0) 31 : : return -EACCES; 32 : : 33 : 0 : res = write(fd, value, size); 34 : 0 : close(fd); 35 [ # # ]: 0 : if (res < 0) 36 : 0 : return -EACCES; 37 : : 38 : : return 0; 39 : : } 40 : : 41 : : int 42 : 0 : roc_dpi_enable(struct roc_dpi *dpi) 43 : : { 44 : 0 : plt_write64(0x1, dpi->rbase + DPI_VDMA_EN); 45 : 0 : return 0; 46 : : } 47 : : 48 : : int 49 : 0 : roc_dpi_disable(struct roc_dpi *dpi) 50 : : { 51 : 0 : plt_write64(0x0, dpi->rbase + DPI_VDMA_EN); 52 : 0 : return 0; 53 : : } 54 : : 55 : : int 56 : 0 : roc_dpi_configure(struct roc_dpi *roc_dpi, uint32_t chunk_sz, uint64_t aura, uint64_t chunk_base) 57 : : { 58 : : struct plt_pci_device *pci_dev; 59 : : dpi_mbox_msg_t mbox_msg; 60 : : uint64_t reg; 61 : : int rc; 62 : : 63 [ # # ]: 0 : if (!roc_dpi) { 64 : 0 : plt_err("roc_dpi is NULL"); 65 : 0 : return -EINVAL; 66 : : } 67 : : 68 : 0 : pci_dev = roc_dpi->pci_dev; 69 : : 70 : 0 : roc_dpi_disable(roc_dpi); 71 : 0 : reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR); 72 [ # # ]: 0 : while (!(reg & BIT_ULL(63))) 73 : : reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR); 74 : : 75 : : plt_write64(0x0, roc_dpi->rbase + DPI_VDMA_REQQ_CTL); 76 : : plt_write64(chunk_base, roc_dpi->rbase + DPI_VDMA_SADDR); 77 : 0 : mbox_msg.u[0] = 0; 78 : 0 : mbox_msg.u[1] = 0; 79 : : /* DPI PF driver expects vfid starts from index 0 */ 80 : 0 : mbox_msg.s.vfid = roc_dpi->vfid; 81 : 0 : mbox_msg.s.cmd = DPI_QUEUE_OPEN; 82 : 0 : mbox_msg.s.csize = chunk_sz; 83 : 0 : mbox_msg.s.aura = aura; 84 : 0 : mbox_msg.s.sso_pf_func = idev_sso_pffunc_get(); 85 : 0 : mbox_msg.s.npa_pf_func = idev_npa_pffunc_get(); 86 : : 87 : 0 : rc = send_msg_to_pf(&pci_dev->addr, (const char *)&mbox_msg, 88 : : sizeof(dpi_mbox_msg_t)); 89 [ # # ]: 0 : if (rc < 0) 90 : 0 : plt_err("Failed to send mbox message %d to DPI PF, err %d", 91 : : mbox_msg.s.cmd, rc); 92 : : 93 : : return rc; 94 : : } 95 : : 96 : : int 97 : 0 : roc_dpi_dev_init(struct roc_dpi *roc_dpi) 98 : : { 99 : 0 : struct plt_pci_device *pci_dev = roc_dpi->pci_dev; 100 : : uint16_t vfid; 101 : : 102 : 0 : roc_dpi->rbase = pci_dev->mem_resource[0].addr; 103 : 0 : vfid = ((pci_dev->addr.devid & 0x1F) << 3) | (pci_dev->addr.function & 0x7); 104 : 0 : vfid -= 1; 105 : 0 : roc_dpi->vfid = vfid; 106 : : 107 : 0 : return 0; 108 : : } 109 : : 110 : : int 111 : 0 : roc_dpi_dev_fini(struct roc_dpi *roc_dpi) 112 : : { 113 : 0 : struct plt_pci_device *pci_dev = roc_dpi->pci_dev; 114 : : dpi_mbox_msg_t mbox_msg; 115 : : uint64_t reg; 116 : : int rc; 117 : : 118 : : /* Wait for SADDR to become idle */ 119 : 0 : reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR); 120 [ # # ]: 0 : while (!(reg & BIT_ULL(63))) 121 : : reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR); 122 : : 123 : 0 : mbox_msg.u[0] = 0; 124 : 0 : mbox_msg.u[1] = 0; 125 : 0 : mbox_msg.s.vfid = roc_dpi->vfid; 126 : 0 : mbox_msg.s.cmd = DPI_QUEUE_CLOSE; 127 : : 128 : 0 : rc = send_msg_to_pf(&pci_dev->addr, (const char *)&mbox_msg, sizeof(dpi_mbox_msg_t)); 129 [ # # ]: 0 : if (rc < 0) 130 : 0 : plt_err("Failed to send mbox message %d to DPI PF, err %d", mbox_msg.s.cmd, rc); 131 : : 132 : 0 : return rc; 133 : : }