linux/drivers/net/ethernet/marvell/octeontx2/af/rvu_sdp.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/* Marvell RVU Admin Function driver
   3 *
   4 * Copyright (C) 2021 Marvell.
   5 *
   6 */
   7
   8#include <linux/pci.h>
   9#include "rvu.h"
  10
  11/* SDP PF device id */
  12#define PCI_DEVID_OTX2_SDP_PF   0xA0F6
  13
  14/* Maximum SDP blocks in a chip */
  15#define MAX_SDP         2
  16
  17/* SDP PF number */
  18static int sdp_pf_num[MAX_SDP] = {-1, -1};
  19
  20bool is_sdp_pfvf(u16 pcifunc)
  21{
  22        u16 pf = rvu_get_pf(pcifunc);
  23        u32 found = 0, i = 0;
  24
  25        while (i < MAX_SDP) {
  26                if (pf == sdp_pf_num[i])
  27                        found = 1;
  28                i++;
  29        }
  30
  31        if (!found)
  32                return false;
  33
  34        return true;
  35}
  36
  37bool is_sdp_pf(u16 pcifunc)
  38{
  39        return (is_sdp_pfvf(pcifunc) &&
  40                !(pcifunc & RVU_PFVF_FUNC_MASK));
  41}
  42
  43bool is_sdp_vf(u16 pcifunc)
  44{
  45        return (is_sdp_pfvf(pcifunc) &&
  46                !!(pcifunc & RVU_PFVF_FUNC_MASK));
  47}
  48
  49int rvu_sdp_init(struct rvu *rvu)
  50{
  51        struct pci_dev *pdev = NULL;
  52        struct rvu_pfvf *pfvf;
  53        u32 i = 0;
  54
  55        while ((i < MAX_SDP) && (pdev = pci_get_device(PCI_VENDOR_ID_CAVIUM,
  56                                                       PCI_DEVID_OTX2_SDP_PF,
  57                                                       pdev)) != NULL) {
  58                /* The RVU PF number is one less than bus number */
  59                sdp_pf_num[i] = pdev->bus->number - 1;
  60                pfvf = &rvu->pf[sdp_pf_num[i]];
  61
  62                pfvf->sdp_info = devm_kzalloc(rvu->dev,
  63                                              sizeof(struct sdp_node_info),
  64                                              GFP_KERNEL);
  65                if (!pfvf->sdp_info)
  66                        return -ENOMEM;
  67
  68                dev_info(rvu->dev, "SDP PF number:%d\n", sdp_pf_num[i]);
  69
  70                put_device(&pdev->dev);
  71                i++;
  72        }
  73
  74        return 0;
  75}
  76
  77int
  78rvu_mbox_handler_set_sdp_chan_info(struct rvu *rvu,
  79                                   struct sdp_chan_info_msg *req,
  80                                   struct msg_rsp *rsp)
  81{
  82        struct rvu_pfvf *pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc);
  83
  84        memcpy(pfvf->sdp_info, &req->info, sizeof(struct sdp_node_info));
  85        dev_info(rvu->dev, "AF: SDP%d max_vfs %d num_pf_rings %d pf_srn %d\n",
  86                 req->info.node_id, req->info.max_vfs, req->info.num_pf_rings,
  87                 req->info.pf_srn);
  88        return 0;
  89}
  90
  91int
  92rvu_mbox_handler_get_sdp_chan_info(struct rvu *rvu, struct msg_req *req,
  93                                   struct sdp_get_chan_info_msg *rsp)
  94{
  95        struct rvu_hwinfo *hw = rvu->hw;
  96        int blkaddr;
  97
  98        if (!hw->cap.programmable_chans) {
  99                rsp->chan_base = NIX_CHAN_SDP_CH_START;
 100                rsp->num_chan = NIX_CHAN_SDP_NUM_CHANS;
 101        } else {
 102                blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NIX, 0);
 103                rsp->chan_base = hw->sdp_chan_base;
 104                rsp->num_chan = rvu_read64(rvu, blkaddr, NIX_AF_CONST1) & 0xFFFUL;
 105        }
 106
 107        return 0;
 108}
 109