ZFCP HBA API Library  1
vlib_sysfs.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: EPL-1.0 */
2 /*
3  * Copyright IBM Corp. 2010, 2024.
4  *
5  * Authors: Sven Schuetz <sven@de.ibm.com>
6  * contains code from vlib_aux.h
7  * by Andreas Herrmann and Stefan Voelkel
8  *
9  * File: vlib_sysfs.h
10  *
11  * Description:
12  * Function declarations and inline functions that use the sysfs.
13  *
14  */
15 
16 #ifndef _VLIB_SYSFS_H_
17 #define _VLIB_SYSFS_H_
18 
19 
20 #define ZFCP_SYSFS_PATH "/sys/bus/ccw/drivers/zfcp"
21 #define FC_HOST_PATH "/sys/class/fc_host"
22 
23 #define ATTR_MAX 80 /* all attributes are only one line */
24 #define DEVNO_LENGTH 8 /* x.x.xxxx -> 8 chars */
25 
31 HBA_STATUS sysfs_createAndReadConfigPorts(struct vlib_adapter *);
33 HBA_STATUS sysfs_getDiscoveredPortAttributes(HBA_PORTATTRIBUTES **,
34  struct vlib_port *);
35 HBA_STATUS sysfs_getAdapterPortAttributes(HBA_PORTATTRIBUTES **,
36  struct vlib_adapter *);
37 HBA_STATUS sysfs_getAdapterAttributes(HBA_ADAPTERATTRIBUTES **,
38  struct vlib_adapter *);
39 HBA_STATUS sysfs_getPortStatistics(HBA_PORTSTATISTICS **,
40  struct vlib_adapter *);
41 int sysfs_getUnitsFromPort(struct vlib_port *);
42 void sysfs_waitForSgDev(char *);
43 
56 static inline HBA_STATUS revalidateRepository(void)
57 {
58  if (!vlib_data.isLoaded)
59  return HBA_STATUS_ERROR;
60 
61  if (!vlib_data.isValid) {
62  if (sysfs_createAndReadConfigAdapter() != HBA_STATUS_OK)
63  return HBA_STATUS_ERROR;
64  }
65 
66  return HBA_STATUS_OK;
67 }
68 
81 static inline int revalidatePorts(struct vlib_adapter *adapter)
82 {
83  if (0 == adapter->ports.allocated)
84  return sysfs_createAndReadConfigPorts(adapter);
85 
86  return 0;
87 }
88 
102 static inline int revalidateUnits(struct vlib_port *port)
103 {
104  if (0 == port->units.allocated)
105  return sysfs_getUnitsFromPort(port);
106 
107  return 0;
108 }
109 
110 #endif /*_VLIB_SYSFS_H_*/
size_t allocated
total number of elements in the array
Definition: vlib.h:425
Represenation of an adapter in the library.
Definition: vlib.h:471
struct block ports
List of ports.
Definition: vlib.h:475
Primary data structure used in the library.
Definition: vlib.h:481
unsigned int isValid
Repositoy valid or not This flag is set for instance if a loss of events is detected.
Definition: vlib.h:484
unsigned int isLoaded
Library loaded or not.
Definition: vlib.h:482
Representation of a FC port in the library.
Definition: vlib.h:440
struct block units
List of units.
Definition: vlib.h:445
HBA_STATUS sysfs_getDiscoveredPortAttributes(HBA_PORTATTRIBUTES **, struct vlib_port *)
Retrieve adapter attributes.
Definition: vlib_sysfs.c:420
HBA_STATUS sysfs_createAndReadConfigPorts(struct vlib_adapter *)
Read and store all discovered ports of an adapter.
Definition: vlib_sysfs.c:236
int sysfs_getUnitsFromPort(struct vlib_port *)
Get unit configuration information for a port.
Definition: vlib_sysfs.c:320
HBA_STATUS sysfs_getPortStatistics(HBA_PORTSTATISTICS **, struct vlib_adapter *)
Retrieve adapter port statistics.
Definition: vlib_sysfs.c:611
HBA_STATUS sysfs_getAdapterAttributes(HBA_ADAPTERATTRIBUTES **, struct vlib_adapter *)
Retrieve adapter attributes.
Definition: vlib_sysfs.c:507
static int revalidateUnits(struct vlib_port *port)
Revalidate units of an adapter and port in the repository.
Definition: vlib_sysfs.h:102
static HBA_STATUS revalidateRepository(void)
Check status of the repository, and possibly revalidate it.
Definition: vlib_sysfs.h:56
static int revalidatePorts(struct vlib_adapter *adapter)
Revalidate ports of an adapter in the repository.
Definition: vlib_sysfs.h:81
HBA_STATUS sysfs_getAdapterPortAttributes(HBA_PORTATTRIBUTES **, struct vlib_adapter *)
Retrieve adapter attributes.
Definition: vlib_sysfs.c:455
HBA_STATUS sysfs_createAndReadConfigAdapter()
Read all adapters from /sys/bus/ccw/drivers/zfcp and add them to the repository.
Definition: vlib_sysfs.c:270