ZFCP HBA API Library 1
vlib_aux.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: EPL-1.0 */
2/*
3 * Copyright IBM Corp. 2003,2010
4 *
5 * Authors: Andreas Herrmann
6 * Stefan Voelkel
7 *
8 * File: vlib_aux.h
9 *
10 * Description:
11 * Auxiliary functions used in the library.
12 *
13 */
14
15#ifndef _VLIB_AUX_H_
16#define _VLIB_AUX_H_
21
22#include "vlib.h"
23
24#define VLIB_GROW_UNITS 8
25#define VLIB_GROW_PORTS 4
26#define VLIB_GROW_ADAPTERS 2
27
28#ifdef min
29# undef min
30#endif
31#define min(a, b) (((a) < (b)) ? (a) : (b))
32
33/*
34 * function declarations
35 */
36
37struct vlib_adapter *getAdapterByIndex(uint32_t);
38struct vlib_adapter *getAdapterByHandle(HBA_HANDLE, HBA_STATUS *);
39struct vlib_adapter *getAdapterByDevid(devid_t);
40struct vlib_adapter *getAdapterByHostNo(unsigned short);
41struct vlib_port *getPortByIndex(const struct vlib_adapter *, const uint32_t);
42struct vlib_port *getPortByWWPN(const struct vlib_adapter *, const wwn_t);
43struct vlib_unit *getUnitByIndex(const struct vlib_port *, const uint32_t);
44struct vlib_unit *getUnitByFcLun(const struct vlib_port *, uint64_t);
45
47int addPortToRepos(struct vlib_adapter *, struct vlib_port *);
48int addUnitToRepos(struct vlib_port *, struct vlib_unit *);
49
50HBA_STATUS getAdapterConfig(void);
51int getUnitsFromPort(struct vlib_port *);
52
53int findIndexByName(char *);
54HBA_HANDLE openAdapterByIndex(HBA_UINT32);
55char *getSgDevFromPort(struct vlib_port *);
56char *getAttachedWLUN(struct vlib_adapter *, struct vlib_port *);
57void detachWLUN(struct vlib_adapter *, struct vlib_port *);
58
59int revalidateAdapters(void);
60int updateAdapter(struct vlib_adapter *adapter);
61void doCloseAdapter(struct vlib_adapter *);
62void closeAllAdapters(void);
63
64HBA_PORTTYPE vlibCharToIntPortType(char *);
65HBA_PORTSTATE vlibCharToIntPortState(char *);
66HBA_PORTSPEED vlibCharToIntPortSpeed(char *);
67HBA_COS vlibCharToIntCOS(char *);
68
69/*
70 * inline functions
71 */
72
78static inline void vlib_wwn_to_HBA_WWN(uint64_t wwn, HBA_WWN *hba)
79{
80 *((uint64_t *)(&hba->wwn)) = wwn;
81}
82
88static inline void vlib_HBA_WWN_to_wwn(HBA_WWN *hba, uint64_t *wwn)
89{
90 *wwn = *((uint64_t *)hba->wwn);
91}
92
98static inline uint32_t vlib_FCID_to_hbaFCID(uint32_t fcid)
99{
100 return fcid << 8;
101}
102
108static inline uint32_t vlib_hbaFCID_to_FCID(uint32_t fcid)
109{
110 return fcid >> 8;
111}
112
113
119static inline void invalidateAllAdapters(void)
120{
121 unsigned int i;
122 struct vlib_adapter *adapter;
123
124 adapter = getAdapterByIndex(0);
125 for (i = 0; i < vlib_data.adapters.used; ++i, ++adapter)
126 adapter->isInvalid = 1;
127}
128
135static inline void markRepositoryInvalid(void)
136{
138
139 vlib_data.isValid = 0;
140
142}
143
144#endif /* _VLIB_AUX_H_ */
size_t used
number of used elements in the array
Definition vlib.h:424
Represenation of an adapter in the library.
Definition vlib.h:471
unsigned int isInvalid
Adapter invalid or not.
Definition vlib.h:472
Primary data structure used in the library.
Definition vlib.h:481
pthread_mutex_t mutex
Protects this structure.
Definition vlib.h:496
unsigned int isValid
Repositoy valid or not This flag is set for instance if a loss of events is detected.
Definition vlib.h:484
struct block adapters
List of adapters In fact this is the anchor of the library's repository.
Definition vlib.h:491
Representation of a FC port in the library.
Definition vlib.h:440
Represenation of an FCP unit in the library.
Definition vlib.h:429
Central header file for the library.
#define VLIB_MUTEX_UNLOCK(mutex)
To unlock a mutex, this macro is used, which checks for errors.
Definition vlib.h:591
#define VLIB_MUTEX_LOCK(mutex)
To lock a mutex, this macro is used, which checks for errors.
Definition vlib.h:568
static void vlib_HBA_WWN_to_wwn(HBA_WWN *hba, uint64_t *wwn)
Convert HBA_WWN to uint64_t – hide ill-favoured type cast.
Definition vlib_aux.h:88
struct vlib_adapter * getAdapterByIndex(uint32_t)
Get an adapter by its index.
Definition vlib_aux.c:115
HBA_HANDLE openAdapterByIndex(HBA_UINT32)
Open an adapter by index.
Definition vlib_aux.c:611
struct vlib_unit * getUnitByIndex(const struct vlib_port *, const uint32_t)
Get an unit by its index.
Definition vlib_aux.c:273
static void markRepositoryInvalid(void)
Mark repositroy of library as invalid. This is appropriate if a loss of events is detected.
Definition vlib_aux.h:135
void closeAllAdapters(void)
Close all adapters in the repository.
Definition vlib_aux.c:666
struct vlib_adapter * getAdapterByHandle(HBA_HANDLE, HBA_STATUS *)
Get an adapter by its handle.
Definition vlib_aux.c:140
struct vlib_adapter * getAdapterByDevid(devid_t)
Get an adapter by its devid.
Definition vlib_aux.c:173
static void invalidateAllAdapters(void)
Mark all adapters in repository as invalid.
Definition vlib_aux.h:119
static uint32_t vlib_FCID_to_hbaFCID(uint32_t fcid)
Convert a FC DID to a FC-HBA PortFcId.
Definition vlib_aux.h:98
int findIndexByName(char *)
Find an adapter index by name.
Definition vlib_aux.c:579
struct vlib_port * getPortByIndex(const struct vlib_adapter *, const uint32_t)
Get a port by its index.
Definition vlib_aux.c:227
int addUnitToRepos(struct vlib_port *, struct vlib_unit *)
Add a unit to the repository.
Definition vlib_aux.c:348
struct vlib_port * getPortByWWPN(const struct vlib_adapter *, const wwn_t)
Get a port by its WWPN.
Definition vlib_aux.c:246
static uint32_t vlib_hbaFCID_to_FCID(uint32_t fcid)
Convert a FC-HBA PortFcId to a FC DID.
Definition vlib_aux.h:108
int addPortToRepos(struct vlib_adapter *, struct vlib_port *)
Add a port from to the repository.
Definition vlib_aux.c:406
struct vlib_adapter * getAdapterByHostNo(unsigned short)
Get an adapter by SCSI Host number as in sysfs.
Definition vlib_aux.c:199
void doCloseAdapter(struct vlib_adapter *)
Close an adapter in the repository.
Definition vlib_aux.c:641
HBA_PORTSPEED vlibCharToIntPortSpeed(char *)
Map the result of a port speed string to the HBA_PORTSPEED int.
Definition vlib_aux.c:807
int addAdapterToRepos(struct vlib_adapter *)
Add an adapter to the repository.
Definition vlib_aux.c:469
int updateAdapter(struct vlib_adapter *adapter)
Update information about ports and units of an adapter.
Definition vlib_aux.c:509
struct vlib_unit * getUnitByFcLun(const struct vlib_port *, uint64_t)
Get an unit by its fclun.
Definition vlib_aux.c:292
HBA_COS vlibCharToIntCOS(char *)
Map the result of a class of service string to an int.
Definition vlib_aux.c:870
char * getAttachedWLUN(struct vlib_adapter *, struct vlib_port *)
Try to attach the report luns wlun and return its name as in "/dev".
Definition vlib_aux.c:922
int revalidateAdapters(void)
Revalidate adapters in the repository.
Definition vlib_aux.c:543
HBA_PORTSTATE vlibCharToIntPortState(char *)
Map the result of a port state string from sysfs to an int.
Definition vlib_aux.c:710
static void vlib_wwn_to_HBA_WWN(uint64_t wwn, HBA_WWN *hba)
Convert uint64_t to HBA_WWN – hide ill-favoured type cast.
Definition vlib_aux.h:78
char * getSgDevFromPort(struct vlib_port *)
Get the first sg device from an adapter.
Definition vlib_aux.c:898
HBA_PORTTYPE vlibCharToIntPortType(char *)
Map the result of a port type string from sysfs to an int.
Definition vlib_aux.c:685
void detachWLUN(struct vlib_adapter *, struct vlib_port *)
Try to detach lun 0.
Definition vlib_aux.c:952