LCOV - code coverage report
Current view: top level - drivers/net/zxdh - zxdh_pci.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 28 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2024 ZTE Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef ZXDH_PCI_H
       6                 :            : #define ZXDH_PCI_H
       7                 :            : 
       8                 :            : #include <stdint.h>
       9                 :            : #include <stdbool.h>
      10                 :            : 
      11                 :            : #include <bus_pci_driver.h>
      12                 :            : 
      13                 :            : #include "zxdh_ethdev.h"
      14                 :            : 
      15                 :            : #define ZXDH_PF_PCIE_ID(pcie_id)  (((pcie_id) & 0xff00) | 1 << 11)
      16                 :            : 
      17                 :            : enum zxdh_msix_status {
      18                 :            :         ZXDH_MSIX_NONE     = 0,
      19                 :            :         ZXDH_MSIX_DISABLED = 1,
      20                 :            :         ZXDH_MSIX_ENABLED  = 2
      21                 :            : };
      22                 :            : 
      23                 :            : /* The bit of the ISR which indicates a device has an interrupt. */
      24                 :            : #define ZXDH_PCI_ISR_INTR    0x1
      25                 :            : /* The bit of the ISR which indicates a device configuration change. */
      26                 :            : #define ZXDH_PCI_ISR_CONFIG  0x2
      27                 :            : /* Vector value used to disable MSI for queue. */
      28                 :            : #define ZXDH_MSI_NO_VECTOR   0x7F
      29                 :            : 
      30                 :            : #define ZXDH_PCI_VRING_ALIGN         4096
      31                 :            : 
      32                 :            : #define ZXDH_NET_F_CSUM              0   /* Host handles pkts w/ partial csum */
      33                 :            : #define ZXDH_NET_F_GUEST_CSUM        1   /* Guest handles pkts w/ partial csum */
      34                 :            : #define ZXDH_NET_F_MTU               3   /* Initial MTU advice. */
      35                 :            : #define ZXDH_NET_F_MAC               5   /* Host has given MAC address. */
      36                 :            : #define ZXDH_NET_F_GUEST_TSO4        7   /* Guest can handle TSOv4 in. */
      37                 :            : #define ZXDH_NET_F_GUEST_TSO6        8   /* Guest can handle TSOv6 in. */
      38                 :            : #define ZXDH_NET_F_GUEST_ECN         9   /* Guest can handle TSO[6] w/ ECN in. */
      39                 :            : #define ZXDH_NET_F_GUEST_UFO         10  /* Guest can handle UFO in. */
      40                 :            : 
      41                 :            : #define ZXDH_NET_F_HOST_UFO          14  /* Host can handle UFO in. */
      42                 :            : #define ZXDH_NET_F_HOST_TSO4         11  /* Host can handle TSOv4 in. */
      43                 :            : #define ZXDH_NET_F_HOST_TSO6         12  /* Host can handle TSOv6 in. */
      44                 :            : #define ZXDH_NET_F_MRG_RXBUF         15  /* Host can merge receive buffers. */
      45                 :            : #define ZXDH_NET_F_STATUS            16  /* zxdh_net_config.status available */
      46                 :            : #define ZXDH_NET_F_MQ                22  /* Device supports Receive Flow Steering */
      47                 :            : #define ZXDH_F_ANY_LAYOUT            27 /* Can the device handle any descriptor layout */
      48                 :            : #define ZXDH_F_VERSION_1             32
      49                 :            : #define ZXDH_F_RING_PACKED           34
      50                 :            : #define ZXDH_F_IN_ORDER              35
      51                 :            : #define ZXDH_F_NOTIFICATION_DATA     38
      52                 :            : 
      53                 :            : #define ZXDH_PCI_CAP_COMMON_CFG  1 /* Common configuration */
      54                 :            : #define ZXDH_PCI_CAP_NOTIFY_CFG  2 /* Notifications */
      55                 :            : #define ZXDH_PCI_CAP_ISR_CFG     3 /* ISR Status */
      56                 :            : #define ZXDH_PCI_CAP_DEVICE_CFG  4 /* Device specific configuration */
      57                 :            : #define ZXDH_PCI_CAP_PCI_CFG     5 /* PCI configuration access */
      58                 :            : 
      59                 :            : /* Status byte for guest to report progress. */
      60                 :            : #define ZXDH_CONFIG_STATUS_RESET           0x00
      61                 :            : #define ZXDH_CONFIG_STATUS_ACK             0x01
      62                 :            : #define ZXDH_CONFIG_STATUS_DRIVER          0x02
      63                 :            : #define ZXDH_CONFIG_STATUS_DRIVER_OK       0x04
      64                 :            : #define ZXDH_CONFIG_STATUS_FEATURES_OK     0x08
      65                 :            : #define ZXDH_CONFIG_STATUS_DEV_NEED_RESET  0x40
      66                 :            : #define ZXDH_CONFIG_STATUS_FAILED          0x80
      67                 :            : #define ZXDH_PCI_QUEUE_ADDR_SHIFT          12
      68                 :            : 
      69                 :            : struct __rte_packed_begin zxdh_net_config {
      70                 :            :         /* The config defining mac address (if ZXDH_NET_F_MAC) */
      71                 :            :         uint8_t    mac[RTE_ETHER_ADDR_LEN];
      72                 :            :         /* See ZXDH_NET_F_STATUS and ZXDH_NET_S_* above */
      73                 :            :         uint16_t   status;
      74                 :            :         uint16_t   max_virtqueue_pairs;
      75                 :            :         uint16_t   mtu;
      76                 :            :         uint32_t   speed;
      77                 :            :         uint8_t    duplex;
      78                 :            : } __rte_packed_end;
      79                 :            : 
      80                 :            : /* This is the PCI capability header: */
      81                 :            : struct zxdh_pci_cap {
      82                 :            :         uint8_t  cap_vndr;   /* Generic PCI field: PCI_CAP_ID_VNDR */
      83                 :            :         uint8_t  cap_next;   /* Generic PCI field: next ptr. */
      84                 :            :         uint8_t  cap_len;    /* Generic PCI field: capability length */
      85                 :            :         uint8_t  cfg_type;   /* Identifies the structure. */
      86                 :            :         uint8_t  bar;        /* Where to find it. */
      87                 :            :         uint8_t  padding[3]; /* Pad to full dword. */
      88                 :            :         uint32_t offset;     /* Offset within bar. */
      89                 :            :         uint32_t length;     /* Length of the structure, in bytes. */
      90                 :            : };
      91                 :            : 
      92                 :            : /* Fields in ZXDH_PCI_CAP_COMMON_CFG: */
      93                 :            : struct zxdh_pci_common_cfg {
      94                 :            :         /* About the whole device. */
      95                 :            :         uint32_t device_feature_select; /* read-write */
      96                 :            :         uint32_t device_feature;    /* read-only */
      97                 :            :         uint32_t guest_feature_select;  /* read-write */
      98                 :            :         uint32_t guest_feature;     /* read-write */
      99                 :            :         uint16_t msix_config;       /* read-write */
     100                 :            :         uint16_t num_queues;        /* read-only */
     101                 :            :         uint8_t  device_status;     /* read-write */
     102                 :            :         uint8_t  config_generation; /* read-only */
     103                 :            : 
     104                 :            :         /* About a specific virtqueue. */
     105                 :            :         uint16_t queue_select;      /* read-write */
     106                 :            :         uint16_t queue_size;        /* read-write, power of 2. */
     107                 :            :         uint16_t queue_msix_vector; /* read-write */
     108                 :            :         uint16_t queue_enable;      /* read-write */
     109                 :            :         uint16_t queue_notify_off;  /* read-only */
     110                 :            :         uint32_t queue_desc_lo;     /* read-write */
     111                 :            :         uint32_t queue_desc_hi;     /* read-write */
     112                 :            :         uint32_t queue_avail_lo;    /* read-write */
     113                 :            :         uint32_t queue_avail_hi;    /* read-write */
     114                 :            :         uint32_t queue_used_lo;     /* read-write */
     115                 :            :         uint32_t queue_used_hi;     /* read-write */
     116                 :            : };
     117                 :            : 
     118                 :            : static inline int32_t
     119                 :            : zxdh_pci_with_feature(struct zxdh_hw *hw, uint64_t bit)
     120                 :            : {
     121   [ #  #  #  #  :          0 :         return (hw->guest_features & (1ULL << bit)) != 0;
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     122                 :            : }
     123                 :            : 
     124                 :            : static inline int32_t
     125                 :            : zxdh_pci_packed_queue(struct zxdh_hw *hw)
     126                 :            : {
     127                 :            :         return zxdh_pci_with_feature(hw, ZXDH_F_RING_PACKED);
     128                 :            : }
     129                 :            : 
     130                 :            : struct zxdh_pci_ops {
     131                 :            :         void     (*read_dev_cfg)(struct zxdh_hw *hw, size_t offset, void *dst, int32_t len);
     132                 :            :         void     (*write_dev_cfg)(struct zxdh_hw *hw, size_t offset, const void *src, int32_t len);
     133                 :            : 
     134                 :            :         uint8_t  (*get_status)(struct zxdh_hw *hw);
     135                 :            :         void     (*set_status)(struct zxdh_hw *hw, uint8_t status);
     136                 :            : 
     137                 :            :         uint64_t (*get_features)(struct zxdh_hw *hw);
     138                 :            :         void     (*set_features)(struct zxdh_hw *hw, uint64_t features);
     139                 :            :         uint16_t (*set_queue_irq)(struct zxdh_hw *hw, struct zxdh_virtqueue *vq, uint16_t vec);
     140                 :            :         uint16_t (*set_config_irq)(struct zxdh_hw *hw, uint16_t vec);
     141                 :            :         uint8_t  (*get_isr)(struct zxdh_hw *hw);
     142                 :            :         uint16_t (*get_queue_num)(struct zxdh_hw *hw, uint16_t queue_id);
     143                 :            :         void     (*set_queue_num)(struct zxdh_hw *hw, uint16_t queue_id, uint16_t vq_size);
     144                 :            : 
     145                 :            :         int32_t  (*setup_queue)(struct zxdh_hw *hw, struct zxdh_virtqueue *vq);
     146                 :            :         void     (*del_queue)(struct zxdh_hw *hw, struct zxdh_virtqueue *vq);
     147                 :            :         void     (*notify_queue)(struct zxdh_hw *hw, struct zxdh_virtqueue *vq);
     148                 :            : };
     149                 :            : 
     150                 :            : struct zxdh_hw_internal {
     151                 :            :         const struct zxdh_pci_ops *zxdh_vtpci_ops;
     152                 :            : };
     153                 :            : 
     154                 :            : #define ZXDH_VTPCI_OPS(hw)  (zxdh_hw_internal[(hw)->port_id].zxdh_vtpci_ops)
     155                 :            : 
     156                 :            : extern struct zxdh_hw_internal zxdh_hw_internal[RTE_MAX_ETHPORTS];
     157                 :            : extern const struct zxdh_pci_ops zxdh_dev_pci_ops;
     158                 :            : 
     159                 :            : void zxdh_pci_reset(struct zxdh_hw *hw);
     160                 :            : void zxdh_pci_read_dev_config(struct zxdh_hw *hw, size_t offset,
     161                 :            :                 void *dst, int32_t length);
     162                 :            : 
     163                 :            : int32_t zxdh_read_pci_caps(struct rte_pci_device *dev, struct zxdh_hw *hw);
     164                 :            : void zxdh_get_pci_dev_config(struct zxdh_hw *hw);
     165                 :            : 
     166                 :            : uint16_t zxdh_pci_get_features(struct zxdh_hw *hw);
     167                 :            : enum zxdh_msix_status zxdh_pci_msix_detect(struct rte_pci_device *dev);
     168                 :            : uint8_t zxdh_pci_isr(struct zxdh_hw *hw);
     169                 :            : void zxdh_pci_reinit_complete(struct zxdh_hw *hw);
     170                 :            : void zxdh_pci_set_status(struct zxdh_hw *hw, uint8_t status);
     171                 :            : 
     172                 :            : #endif /* ZXDH_PCI_H */

Generated by: LCOV version 1.14