Skip to content

Commit

Permalink
kmod/vdpa: read vendor data PCI capability
Browse files Browse the repository at this point in the history
Read the vendor data PCI capability to determine the type of device
being emulated.

Signed-off-by: Shijith Thotton <sthotton@marvell.com>
Change-Id: I1ddd94329e5e3e68e8a46ea255d7ffc4d1c1d9a9
Reviewed-on: https://sj1git1.cavium.com/c/IP/SW/dataplane/dpu-offload/+/137096
Tested-by: sa_ip-toolkits-Jenkins <sa_ip-toolkits-jenkins@marvell.com>
Reviewed-by: Nithin Kumar Dabilpuram <ndabilpuram@marvell.com>
Reviewed-by: Jerin Jacob <jerinj@marvell.com>
  • Loading branch information
Shijith Thotton authored and jerinjacobk committed Oct 16, 2024
1 parent c1d880f commit bb22e1b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
24 changes: 24 additions & 0 deletions kmod/vdpa/octeon_ep/octep_vdpa.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <linux/pci_regs.h>
#include <linux/vdpa.h>
#include <linux/virtio_pci_modern.h>
#include <uapi/linux/virtio_crypto.h>
#include <uapi/linux/virtio_net.h>
#include <uapi/linux/virtio_blk.h>
#include <uapi/linux/virtio_config.h>
Expand Down Expand Up @@ -52,6 +53,28 @@ struct octep_vring_info {
phys_addr_t notify_pa;
};

enum octep_pci_vndr_cfg_type {
OCTEP_PCI_VNDR_CFG_TYPE_VIRTIO_ID,
OCTEP_PCI_VNDR_CFG_TYPE_MAX,
};

struct octep_pci_vndr_data {
u8 cap_vndr;
u8 cap_next;
u8 cap_len;
u8 cfg_type;
u16 vendor_id;
u8 id;
u8 bar;
union {
u64 data;
struct {
u32 offset;
u32 length;
};
};
};

struct octep_hw {
struct pci_dev *pdev;
u8 __iomem *base[PCI_STD_NUM_BARS];
Expand All @@ -69,6 +92,7 @@ struct octep_hw {
u32 config_size;
int nb_irqs;
int *irqs;
u8 dev_id;
};

u8 octep_hw_get_status(struct octep_hw *oct_hw);
Expand Down
35 changes: 34 additions & 1 deletion kmod/vdpa/octeon_ep/octep_vdpa_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,14 @@ u16 octep_get_vq_size(struct octep_hw *oct_hw)

static u32 octep_get_config_size(struct octep_hw *oct_hw)
{
return sizeof(struct virtio_net_config);
switch (oct_hw->dev_id) {
case VIRTIO_ID_NET:
return sizeof(struct virtio_net_config);
case VIRTIO_ID_CRYPTO:
return sizeof(struct virtio_crypto_config);
default:
return 0;
}
}

static void __iomem *octep_get_cap_addr(struct octep_hw *oct_hw, struct virtio_pci_cap *cap)
Expand Down Expand Up @@ -416,6 +423,21 @@ static int octep_pci_signature_verify(struct octep_hw *oct_hw)
return 0;
}

static void octep_vndr_data_process(struct octep_hw *oct_hw,
struct octep_pci_vndr_data *vndr_data)
{
switch (vndr_data->id) {
case OCTEP_PCI_VNDR_CFG_TYPE_VIRTIO_ID:
oct_hw->dev_id = (u8)vndr_data->data;
break;
default:
dev_err(&oct_hw->pdev->dev, "Invalid vendor data id %u\n",
vndr_data->id);
break;
}
}

#define VIRTIO_PCI_CAP_VENDOR_CFG 9
int octep_hw_caps_read(struct octep_hw *oct_hw, struct pci_dev *pdev)
{
struct octep_mbox __iomem *mbox;
Expand Down Expand Up @@ -466,6 +488,17 @@ int octep_hw_caps_read(struct octep_hw *oct_hw, struct pci_dev *pdev)
case VIRTIO_PCI_CAP_ISR_CFG:
oct_hw->isr = octep_get_cap_addr(oct_hw, &cap);
break;
case VIRTIO_PCI_CAP_VENDOR_CFG:
struct octep_pci_vndr_data vndr_data;

octep_pci_caps_read(oct_hw, &vndr_data, sizeof(vndr_data), pos);
if (vndr_data.vendor_id != PCI_VENDOR_ID_CAVIUM) {
dev_err(dev, "Invalid vendor data\n");
return -EINVAL;
}

octep_vndr_data_process(oct_hw, &vndr_data);
break;
}

pos = cap.cap_next;
Expand Down
4 changes: 3 additions & 1 deletion kmod/vdpa/octeon_ep/octep_vdpa_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ static u32 octep_vdpa_get_generation(struct vdpa_device *vdpa_dev)

static u32 octep_vdpa_get_device_id(struct vdpa_device *vdpa_dev)
{
return VIRTIO_ID_NET;
struct octep_hw *oct_hw = vdpa_to_octep_hw(vdpa_dev);

return oct_hw->dev_id;
}

static u32 octep_vdpa_get_vendor_id(struct vdpa_device *vdpa_dev)
Expand Down

0 comments on commit bb22e1b

Please sign in to comment.