dpdk/drivers/raw/octeontx2_dma/otx2_dpi_msg.c
<<
>>
Prefs
   1/* SPDX-License-Identifier: BSD-3-Clause
   2 * Copyright(C) 2019 Marvell International Ltd.
   3 */
   4
   5#ifndef _DPI_MSG_H_
   6#define _DPI_MSG_H_
   7
   8#include <dirent.h>
   9#include <fcntl.h>
  10#include <string.h>
  11#include <unistd.h>
  12
  13#include "otx2_dpi_rawdev.h"
  14
  15/* DPI PF DBDF information macro's */
  16#define DPI_PF_DBDF_DOMAIN      0
  17#define DPI_PF_DBDF_BUS         5
  18#define DPI_PF_DBDF_DEVICE      0
  19#define DPI_PF_DBDF_FUNCTION    0
  20
  21#define DPI_PF_MBOX_SYSFS_ENTRY "dpi_device_config"
  22
  23union dpi_mbox_message_u {
  24        uint64_t u[2];
  25        struct dpi_mbox_message_s {
  26                /* VF ID to configure */
  27                uint64_t vfid           :4;
  28                /* Command code */
  29                uint64_t cmd            :4;
  30                /* Command buffer size in 8-byte words */
  31                uint64_t csize          :14;
  32                /* aura of the command buffer */
  33                uint64_t aura           :20;
  34                /* SSO PF function */
  35                uint64_t sso_pf_func    :16;
  36                /* NPA PF function */
  37                uint64_t npa_pf_func    :16;
  38        } s;
  39};
  40
  41static inline int
  42send_msg_to_pf(struct rte_pci_addr *pci, const char *value, int size)
  43{
  44        char buff[255] = { 0 };
  45        int res, fd;
  46
  47        res = snprintf(buff, sizeof(buff), "%s/" PCI_PRI_FMT "/%s",
  48                       rte_pci_get_sysfs_path(), pci->domain,
  49                       pci->bus, DPI_PF_DBDF_DEVICE & 0x7,
  50                       DPI_PF_DBDF_FUNCTION & 0x7, DPI_PF_MBOX_SYSFS_ENTRY);
  51        if ((res < 0) || ((size_t)res > sizeof(buff)))
  52                return -ERANGE;
  53
  54        fd = open(buff, O_WRONLY);
  55        if (fd < 0)
  56                return -EACCES;
  57        res = write(fd, value, size);
  58        close(fd);
  59        if (res < 0)
  60                return -EACCES;
  61
  62        return 0;
  63}
  64
  65int
  66otx2_dpi_queue_open(struct dpi_vf_s *dpivf, uint32_t size, uint32_t gaura)
  67{
  68        union dpi_mbox_message_u mbox_msg;
  69        int ret = 0;
  70
  71        /* DPI PF driver expects vfid starts from index 0 */
  72        mbox_msg.s.vfid = dpivf->vf_id;
  73        mbox_msg.s.cmd = DPI_QUEUE_OPEN;
  74        mbox_msg.s.csize = size;
  75        mbox_msg.s.aura = gaura;
  76        mbox_msg.s.sso_pf_func = otx2_sso_pf_func_get();
  77        mbox_msg.s.npa_pf_func = otx2_npa_pf_func_get();
  78
  79        ret = send_msg_to_pf(&dpivf->dev->addr, (const char *)&mbox_msg,
  80                                sizeof(mbox_msg));
  81        if (ret < 0)
  82                otx2_dpi_dbg("Failed to send mbox message to dpi pf");
  83
  84        return ret;
  85}
  86
  87int
  88otx2_dpi_queue_close(struct dpi_vf_s *dpivf)
  89{
  90        union dpi_mbox_message_u mbox_msg;
  91        int ret = 0;
  92
  93        /* DPI PF driver expects vfid starts from index 0 */
  94        mbox_msg.s.vfid = dpivf->vf_id;
  95        mbox_msg.s.cmd = DPI_QUEUE_CLOSE;
  96
  97        ret = send_msg_to_pf(&dpivf->dev->addr, (const char *)&mbox_msg,
  98                                sizeof(mbox_msg));
  99        if (ret < 0)
 100                otx2_dpi_dbg("Failed to send mbox message to dpi pf");
 101
 102        return ret;
 103}
 104
 105#endif /* _DPI_MSG_H_ */
 106