libzpci: Introduce libzpci

This introduces libzpci which is a library intended to handle s390x
specific PCI attributes and peculiarities. As a first step it introduces
code to list PCI devices on s390x including an initial set of s390x
specific attributes like FID, PFT, UID etc. It also collects information
on network device associated with a particular PCI function. The
included example serves as a demonstration of using libzpci to list PCI
devices.

Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Niklas Schnelle
2023-11-14 17:29:00 +01:00
committed by Jan Höppner
parent c54a915a90
commit 3a4c20b443
6 changed files with 429 additions and 1 deletions

70
include/lib/pci_list.h Normal file
View File

@@ -0,0 +1,70 @@
/**
* @defgroup pci_list_h libzpci: zPCI device handling
* @{
* @brief Work with zPCI devices
*
* Copyright IBM Corp. 2024
*
* s390-tools is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIB_ZPCI_PCI_LIST_H
#define LIB_ZPCI_PCI_LIST_H
#include <stdint.h>
#include <stdbool.h>
#include "util_list.h"
enum zpci_pft {
ZPCI_PFT_UNCLASSIFIED = 0x00,
ZPCI_PFT_ROCE_EXPRESS = 0x02,
ZPCI_PFT_ROCE_EXPRESS2 = 0x0a,
ZPCI_PFT_CNW = 0x0d,
ZPCI_PFT_NETH = 0x0c,
ZPCI_PFT_NETD = 0x0f,
ZPCI_PFT_NVME = 0x0b,
ZPCI_PFT_ISM = 0x05
};
struct zpci_dev {
struct util_list_node entry;
/* PCI Domain */
uint32_t domain_nr;
/* PCI Bus (8 bits), Device (5 bits), Function (3 bits) */
union {
uint16_t val;
struct {
uint16_t bus : 8;
uint16_t dev : 5;
uint16_t fn : 3;
};
} bdf;
/* Function attributes (see linux/Documentation/arch/s390/pci.rst) */
uint32_t fid;
uint32_t uid;
uint16_t pchid;
uint16_t vfn;
uint8_t port;
enum zpci_pft pft;
bool uid_is_unique;
/* Configuration state 0 - Standby, 1 Configured */
bool conf;
/* Associated netdevs if any */
int num_netdevs;
char **netdevs;
};
struct util_list *zpci_dev_list(void);
void zpci_free_dev_list(struct util_list *zpci_list);
void zpci_free_dev(struct zpci_dev *zdev);
char *zpci_pci_addr(struct zpci_dev *zdev);
const char *zpci_pft_str(struct zpci_dev *zdev);
#endif /* LIB_ZPCI_PCI_LIST_H */