FlxCard
Loading...
Searching...
No Matches
Driver interaction

Functions

void FlxCard::card_open (int device_nr, u_int lock_mask, bool read_config=false, bool ignore_version=false)
 
void FlxCard::card_close ()
 
static u_int FlxCard::number_of_cards ()
 
static u_int FlxCard::number_of_devices ()
 
static device_list_t FlxCard::device_list ()
 
static int FlxCard::card_to_device_number (int card_number)
 
u_int FlxCard::lock_mask (int device_nr)
 
u_int FlxCard::get_lock_mask (int device_nr)
 
u_long FlxCard::openBackDoor (int bar)
 
u_long FlxCard::bar0Address ()
 
u_long FlxCard::bar1Address ()
 
u_long FlxCard::bar2Address ()
 

Detailed Description

A set of functions that interact with the driver, there are methods to open the API for instance, but also to open an alternative (backdoor) way to reading and writing the registers by memory-mapping a struct directly on the register map (BAR space).

Function Documentation

◆ card_open()

void FlxCard::card_open ( int device_nr,
u_int lock_mask,
bool read_config = false,
bool ignore_version = false )

Opens the flx driver and links one Flx PCIe card to the FlxCard object and has to be called before any other reference to the method is made. In case of problems, check (more /proc/flx) if the driver is running and if it can see all cards. The method also checks if the major version of the register map of the F/W running on the FLX card matches with the version of the “regmap” library. This is to prevent running the API on incompatible FLX cards.

Each FLX device has a number of resources that cannot be shared by multiple processes, such as a DMA controller or the onboard I2C-bus. The purpose of the resource locking bits is to allow a process to declare to the driver that it requires exclusive access to such a resource. If a resource is locked by a process, the driver will refuse other processes that request access to the same resource. In such a case card_open() throws an exception. The parameter lock_mask passes a collection of bits to the driver. These bits are defined in FlxCard.h. Currently the following resources are defined:

#define LOCK_DMA0    1 
#define LOCK_DMA1    2 
#define LOCK_I2C     4 
#define LOCK_FLASH   8 
#define LOCK_ELINK   16 
#define LOCK_ALL     0xffffffff 

Note that DMA-related lock bits are currently also located in bits 16 and up: there is copy of LOCK_DMA0 and LOCK_DMA1 (in bit 16 and 17 resp.) and space for more DMA lock bits (required for next-generation firmware versions).

Example: To lock access to DMA1 and the FLASH memory of the first FLX device:

card_open( 0, LOCK_DMA1 | LOCK_FLASH )

The lock will be held until the owning process calls card_close(). If a process terminates with an error the driver will release the resources that were locked by that process. Users can find an overview of what resources are locked by looking at the content of /proc/flx. Processes that do not request any locks still have full access to the respective resources. That is to say that a process that does not lock DMA1 still can call the DMA related methods of the API. The method lock_mask() can be called to figure out what resources are locked. This was done on purpose because the application programmers know best if their applications (for example for diagnostic purposes) should be able to run even if a resource is locked. Consequently, the application programmers bear the responsibility for using the resource locking in a correct way.

Errors In case of an error, an exception is thrown.

Parameters
device_nrThe number of the FLX device (0…N-1) that is to be linked to the object
lock_maskThe resources that are to be locked, defined as a bit mask
read_configRead and locally store the (e-)link configuration
ignore_versionFor some tools it may be useful to be able to open the FELIX device despite a mismatch between software and firmware version (in that case results in a warning, but does not throw an exception)

◆ card_close()

void FlxCard::card_close ( )

Unlinks a Flx PCIe card. It must be called before closing the application.

Errors In case of an error, an exception is thrown.

◆ number_of_cards()

static u_int FlxCard::number_of_cards ( )
static

Returns the number of FLX cards that are installed in the host computer, taking into account single-device FLX-709 cards. As it is a static method you do not have to instantiate an FlxCard object to call it. For errors see method number_of_devices().

◆ number_of_devices()

static u_int FlxCard::number_of_devices ( )
static

Returns the number of FLX devices (PCIe endpoints) that are installed in the host computer. As it is a static method you do not have to instantiate an FlxCard object to call it.

Errors In case of an error, no exception is thrown but “0” is returned. Therefore “zero cards found” can also mean that:

  • the flx driver was not running
  • the device node /dev/flx was missing
  • the "GETCARDS" ioctl() of the flx driver did not work

◆ device_list()

static device_list_t FlxCard::device_list ( )
static

Returns a structure with information about the cards and devices installed in the PC. As it is a static method you do not have to instantiate an FlxCard object to call it.

The parameter device_list_t.n_devices gives the total number of devices. It is identical to the value returned by number_of_devices() The value of device_list_t.cdmap[device][0] (with device = 0...(device_list_t.n_devices-1 ) is the type of the card as read from the CARD_TYPE register (offset 0xA0 of BAR2) The value of device_list_t.cdmap[device][1] (with device = 0...(device_list_t.n_devices-1 ) is the relative number of the device with respect to the card. That means that for a FLX-709 and FLX-710 it will always be "0" because these are single device cards. For a FLX-711, FLX-712 or FLX-128 it can be "0" or "1".

Errors In case of an error, an exception is thrown.

◆ card_to_device_number()

static int FlxCard::card_to_device_number ( int card_number)
static

Returns the FELIX device number associated with the first device of the selected card number. if for example the host machine contains two FLX-712 cards then card 0 is accessed through device 0, and card 1 through device 2. If on the other hand there is one FLX-709 and one FLX-712 card in the machine, then it could be either devices 0 and 1 or devices 0 and 2, depending on the order in which the cards are enumerated by the host system. This function is used by tools that act on a card rather than a device (for example, card I2C-bus access is through device 0 of the card only).

Parameters
card_numberThe number of the FLX card (0…N-1) in the host machine

◆ lock_mask()

u_int FlxCard::lock_mask ( int device_nr)

Returns information about a device's resources that are currently locked by other instances of FlxCard objects, which may reside in either the same process or in different processes. The value returned is a global resource-lock value retrieved from the driver. The individual lock bits are declared in FlxCard.h

Parameters
device_nrThe number of the FLX device (0…N-1)

Example:

FlxCard flxcard;
u_int lock_bits = flxcard.lock_mask( 0 );
if( lock_mask & LOCK_DMA1 )
cout << "Device 0 DMA1 is locked (by others)"
Definition FlxCard.h:450
u_int lock_mask(int device_nr)

Note This method can be called without first calling open_card().

Errors In case of an error, an exception is thrown.

◆ openBackDoor()

u_long FlxCard::openBackDoor ( int bar)

Returns the PCI base address of the specified PCI register block.

Parameters
barThe number of a BAR register block; legal values are 0, 1 or 2
Returns
the PCI base address of the specified PCI register block

◆ bar0Address()

u_long FlxCard::bar0Address ( )
inline

Is an alias for openBackDoor(0).

◆ bar1Address()

u_long FlxCard::bar1Address ( )
inline

Is an alias for openBackDoor(1).

◆ bar2Address()

u_long FlxCard::bar2Address ( )
inline

Is an alias for openBackDoor(2).