Commit d8823685 authored by Lucas Russo's avatar Lucas Russo

Merge branch 'devel' into smio-timing

parents 81e9fd83 acbe7be1
......@@ -213,7 +213,8 @@ the PCIe kernel driver.
If the PCIe driver is already installed, you could
run it without superuser.
./compile.sh <board type = [ml605|afcv3]>
Usage: ./compile.sh [-b <board>] [-a <applications>] [-e <with examples = yes/no>]
[-l <with library linking = yes/no>] [-d <with driver = yes/no>] [-x <extra flags>]
### Client
......@@ -223,10 +224,14 @@ Change to the Client API folder
Compile the library, with debug info
make ERRHAND_DBG=y ERRHAND_MIN_LEVEL=DBG_MIN_TRACE \
make BOARD=<board> ERRHAND_DBG=y ERRHAND_MIN_LEVEL=DBG_MIN_TRACE \
ERRHAND_SUBSYS_ON=’”(DBG_DEV_MNGR | DBG_DEV_IO | DBG_SM_IO | \
DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)”’
or
sudo ./compile.sh [<board>]
Install the library
sudo make install
......
......@@ -27,7 +27,7 @@ int sdbfs_fread(struct sdbfs *fs, int offset, void *buf, int count)
return -ENOENT;
if (offset < 0)
offset = fs->read_offset;
if (offset + count > fs->f_len)
if ((unsigned int)(offset + count) > fs->f_len)
count = fs->f_len - offset;
ret = count;
if (fs->data)
......@@ -47,7 +47,7 @@ int sdbfs_fwrite(struct sdbfs *fs, int offset, void *buf, int count)
return -ENOENT;
if (offset < 0)
offset = fs->read_offset;
if (offset + count > fs->f_len)
if ((unsigned int)(offset + count) > fs->f_len)
count = fs->f_len - offset;
ret = count;
if (fs->data)
......@@ -67,7 +67,7 @@ int sdbfs_ferase(struct sdbfs *fs, int offset, int count)
return -ENOENT;
if (offset < 0)
offset = fs->read_offset;
if (offset + count > fs->f_len)
if ((unsigned int)(offset + count) > fs->f_len)
count = fs->f_len - offset;
ret = count;
if (fs->data)
......
......@@ -90,7 +90,7 @@ static struct sdb_device *sdbfs_readentry(struct sdbfs *fs,
if (fs->flags & SDBFS_F_CONVERT32) {
uint32_t *p = (void *)&fs->current_record;
int i;
unsigned int i;
for (i = 0; i < sizeof(fs->current_record) / sizeof(*p); i++)
p[i] = ntohl(p[i]);
......@@ -199,7 +199,7 @@ int sdbfs_open_name(struct sdbfs *fs, const char *name)
return -ENOENT;
sdbfs_scan(fs, 1); /* new scan: get the interconnect and igore it */
while ( (d = sdbfs_scan(fs, 0)) != NULL) {
if (strncmp(name, d->sdb_component.product.name, len))
if (strncmp(name, (const char*)d->sdb_component.product.name, len))
continue;
if (len < 19 && d->sdb_component.product.name[len] != ' ')
continue;
......
......@@ -77,6 +77,13 @@ typedef enum _smpr_err_e smpr_err_e;
/* Opaque sm_pr_t structure */
typedef struct _smpr_t smpr_t;
/* Opaque smpr_spi_t structure */
typedef struct _smpr_spi_t smpr_spi_t;
/* Opaque smpr_i2c_t structure */
typedef struct _smpr_i2c_t smpr_i2c_t;
/* Opaque smpr_bsmp_t structure */
typedef struct _smpr_bsmp_t smpr_bsmp_t;
/* Forward smch_err_e declaration enumeration */
typedef enum _smch_err_e smch_err_e;
/* Opaque sm_ch_24aa64_t structure */
......
......@@ -24,18 +24,16 @@
#define WBGEN2_SIGN_EXTEND(value, bits) (((value) & (1<<bits) ? ~((1<<(bits))-1): 0 ) | (value))
#endif
#define AD9510_TRASNS_SIZE 24 /* in bits */
/* AD9510 Instruction Header for 24-bit transfers */
/* AD9510 Transfer type field */
#define AD9510_HDR_RW_SIZE 1
#define AD9510_HDR_RW_SHIFT 23
#define AD9510_HDR_RW_SHIFT 15
#define AD9510_HDR_RW WBGEN2_GEN_MASK(AD9510_HDR_RW_SHIFT, \
AD9510_HDR_RW_SIZE)
/* AD9510 Byte transfer field */
#define AD9510_HDR_BT_SIZE 2
#define AD9510_HDR_BT_SHIFT 21
#define AD9510_HDR_BT_SHIFT 13
#define AD9510_HDR_BT_MASK WBGEN2_GEN_MASK(AD9510_HDR_BT_SHIFT, \
AD9510_HDR_BT_SIZE)
#define AD9510_HDR_BT_W(value) WBGEN2_GEN_WRITE(value, AD9510_HDR_BT_SHIFT, \
......@@ -46,7 +44,7 @@
/* AD9510 Address field. Only the bits 0 to 6 are available. The remaining 7 to 12
* are fixed to 0, as mandated by the AD9510 rev. B datasheet */
#define AD9510_HDR_ADDR_SIZE 7
#define AD9510_HDR_ADDR_SHIFT 8
#define AD9510_HDR_ADDR_SHIFT 0
#define AD9510_HDR_ADDR_MASK WBGEN2_GEN_MASK(AD9510_HDR_ADDR_SHIFT, \
AD9510_HDR_ADDR_SIZE)
#define AD9510_HDR_ADDR_W(value) WBGEN2_GEN_WRITE(value, AD9510_HDR_ADDR_SHIFT, \
......@@ -54,6 +52,14 @@
#define AD9510_HDR_ADDR_R(reg) WBGEN2_GEN_READ(reg, AD9510_HDR_ADDR_SHIFT, \
AD9510_HDR_ADDR_SIZE)
/* Pad bytes to 16-bit */
#define AD9510_HDR_ADDR_PAD_SIZE 6
#define AD9510_INSTADDR_SIZE (AD9510_HDR_RW_SIZE + \
AD9510_HDR_BT_SIZE + \
AD9510_HDR_ADDR_PAD_SIZE + \
AD9510_HDR_ADDR_SIZE)
/* AD9510 Data for 24-bit transfers */
#define AD9510_DATA_SIZE 8
#define AD9510_DATA_SHIFT 0
......@@ -64,6 +70,8 @@
#define AD9510_DATA_R(reg) WBGEN2_GEN_READ(reg, AD9510_DATA_SHIFT, \
AD9510_DATA_SIZE)
#define AD9510_TRANS_SIZE (AD9510_INSTADDR_SIZE+AD9510_DATA_SIZE) /* in bits */
/* AD9510 Register map, as described by the AD9510 reb. B datasheet. Not all of them
* are descried here, just the ones we use */
#define AD9510_REG_CFG_SERIAL 0x00
......
......@@ -44,13 +44,13 @@
/* ISLA216P Transfer type field */
#define ISLA216P_HDR_RW_SIZE 1
#define ISLA216P_HDR_RW_SHIFT 23
#define ISLA216P_HDR_RW_SHIFT 15
#define ISLA216P_HDR_RW WBGEN2_GEN_MASK(ISLA216P_HDR_RW_SHIFT, \
ISLA216P_HDR_RW_SIZE)
/* ISLA216P Byte transfer field */
#define ISLA216P_HDR_BT_SIZE 2
#define ISLA216P_HDR_BT_SHIFT 21
#define ISLA216P_HDR_BT_SHIFT 13
#define ISLA216P_HDR_BT_MASK WBGEN2_GEN_MASK(ISLA216P_HDR_BT_SHIFT, \
ISLA216P_HDR_BT_SIZE)
#define ISLA216P_HDR_BT_W(value) WBGEN2_GEN_WRITE(value, ISLA216P_HDR_BT_SHIFT, \
......@@ -60,7 +60,7 @@
/* ISLA216P Address field */
#define ISLA216P_HDR_ADDR_SIZE 13
#define ISLA216P_HDR_ADDR_SHIFT 8
#define ISLA216P_HDR_ADDR_SHIFT 0
#define ISLA216P_HDR_ADDR_MASK WBGEN2_GEN_MASK(ISLA216P_HDR_ADDR_SHIFT, \
ISLA216P_HDR_ADDR_SIZE)
#define ISLA216P_HDR_ADDR_W(value) WBGEN2_GEN_WRITE(value, ISLA216P_HDR_ADDR_SHIFT, \
......@@ -275,8 +275,8 @@
ISLA216P_NAPSLP_SIZE)
#define ISLA216P_NAPSLP_PIN_CONTROL 0
#define ISLA216P_NAPSLP_NORMAL_OPERATION (1<<0)
#define ISLA216P_NAPSLP_NAP_MODE (1<<1)
#define ISLA216P_NAPSLP_SLEEP_MODE (1<<2)
#define ISLA216P_NAPSLP_NAP_MODE (1<<1)
#define ISLA216P_NAPSLP_SLEEP_MODE (1<<2)
#endif
......@@ -56,7 +56,7 @@ typedef struct {
/* Creates a new instance of Device Information */
devio_t * devio_new (char *name, uint32_t id, char *endpoint_dev,
llio_type_e type, char *endpoint_broker, int verbose,
const llio_ops_t *reg_ops, char *endpoint_broker, int verbose,
const char *log_file_name);
/* Destroy an instance of the Device Information */
devio_err_e devio_destroy (devio_t **self_p);
......
......@@ -15,8 +15,8 @@ extern "C" {
/***************** Our methods *****************/
/* Creates a new instance of the SMCH 24AA64 */
smch_24aa64_t * smch_24aa64_new (smio_t *parent, uint64_t base, uint32_t addr,
int verbose);
smch_24aa64_t * smch_24aa64_new (smio_t *parent, uint64_t base,
const smpr_proto_ops_t *reg_ops, int verbose);
/* Destroy an instance of the SMCH 24AA64 */
smch_err_e smch_24aa64_destroy (smch_24aa64_t **self_p);
......@@ -30,9 +30,6 @@ smch_err_e smch_24aa64_write_block (smch_24aa64_t *self, uint16_t addr, const ui
smch_err_e smch_24aa64_read_block (smch_24aa64_t *self, uint16_t addr, uint32_t *data,
size_t size);
/* Probe bus for I2C devices */
ssize_t smch_24aa64_probe_bus (smch_24aa64_t *self);
#ifdef __cplusplus
}
#endif
......
......@@ -15,8 +15,8 @@ extern "C" {
/***************** Our methods *****************/
/* Creates a new instance of the SMCH AD9510 */
smch_ad9510_t * smch_ad9510_new (smio_t *parent, uint64_t base, uint32_t ss,
int verbose);
smch_ad9510_t * smch_ad9510_new (smio_t *parent, uint64_t base,
const smpr_proto_ops_t *reg_ops, int verbose);
/* Destroy an instance of the SMCH AD9510 */
smch_err_e smch_ad9510_destroy (smch_ad9510_t **self_p);
......
......@@ -15,8 +15,8 @@ extern "C" {
/***************** Our methods *****************/
/* Creates a new instance of the SMCH ISLA216P */
smch_isla216p_t * smch_isla216p_new (smio_t *parent, uint64_t base, uint32_t ss,
int verbose);
smch_isla216p_t * smch_isla216p_new (smio_t *parent, uint64_t base,
const smpr_proto_ops_t *reg_ops, int verbose);
/* Destroy an instance of the SMCH ISLA216P */
smch_err_e smch_isla216p_destroy (smch_isla216p_t **self_p);
......
......@@ -17,8 +17,8 @@ extern "C" {
/***************** Our methods *****************/
/* Creates a new instance of the SMCH PCA9547 */
smch_pca9547_t * smch_pca9547_new (smio_t *parent, uint64_t base, uint32_t addr,
int verbose);
smch_pca9547_t * smch_pca9547_new (smio_t *parent, uint64_t base,
const smpr_proto_ops_t *reg_ops, int verbose);
/* Destroy an instance of the SMCH PCA9547 */
smch_err_e smch_pca9547_destroy (smch_pca9547_t **self_p);
......
......@@ -15,7 +15,7 @@ extern "C" {
/***************** Our methods *****************/
/* Creates a new instance of the SMCH RFFE */
smch_rffe_t * smch_rffe_new (smio_t *parent, int verbose);
smch_rffe_t * smch_rffe_new (smio_t *parent, const smpr_proto_ops_t *reg_ops, int verbose);
/* Destroy an instance of the SMCH RFFE */
smch_err_e smch_rffe_destroy (smch_rffe_t **self_p);
......
......@@ -15,8 +15,8 @@ extern "C" {
/***************** Our methods *****************/
/* Creates a new instance of the SMCH SI57X */
smch_si57x_t * smch_si57x_new (smio_t *parent, uint64_t base, uint32_t addr,
int verbose);
smch_si57x_t * smch_si57x_new (smio_t *parent, uint64_t base,
const smpr_proto_ops_t *reg_ops, int verbose);
/* Destroy an instance of the SMCH SI57X */
smch_err_e smch_si57x_destroy (smch_si57x_t **self_p);
......@@ -30,9 +30,6 @@ smch_err_e smch_si57x_read_8 (smch_si57x_t *self, uint8_t addr,
smch_err_e smch_si57x_read_block (smch_si57x_t *self, uint8_t addr,
uint8_t *data, size_t size);
/* Probe bus for I2C devices */
ssize_t smch_si57x_probe_bus (smch_si57x_t *self);
/* Get Si57X divider values */
smch_err_e smch_si57x_get_divs (smch_si57x_t *self, uint64_t *rfreq,
unsigned int *n1, unsigned int *hs_div);
......
......@@ -19,37 +19,29 @@ extern "C" {
#define SMPR_WB_REG_2_BYTE 4 /* 32-bit word */
#define SMPR_WB_REG_2_BIT (SMPR_WB_REG_2_BYTE*SMPR_BYTE_2_BIT)
typedef enum {
SMPR_SPI = 0,
SMPR_I2C,
SMPR_BSMP,
SMPR_1WIRE,
SMPR_GPIO,
SMPR_BYPASS
} smpr_type_e;
/* Open protocol */
typedef int (*proto_open_fp) (smpr_t *self, uint64_t base, void *args);
/* Release protocol */
typedef int (*proto_release_fp) (smpr_t *self);
/* Read data from protocol */
typedef ssize_t (*proto_read_16_fp) (smpr_t *self, uint64_t offs, uint16_t *data, uint32_t flags);
typedef ssize_t (*proto_read_32_fp) (smpr_t *self, uint64_t offs, uint32_t *data, uint32_t flags);
typedef ssize_t (*proto_read_64_fp) (smpr_t *self, uint64_t offs, uint64_t *data, uint32_t flags);
typedef ssize_t (*proto_read_16_fp) (smpr_t *self, size_t size_offs, uint64_t offs, uint16_t *data);
typedef ssize_t (*proto_read_32_fp) (smpr_t *self, size_t size_offs, uint64_t offs, uint32_t *data);
typedef ssize_t (*proto_read_64_fp) (smpr_t *self, size_t size_offs, uint64_t offs, uint64_t *data);
/* Write data to protocol */
typedef ssize_t (*proto_write_16_fp) (smpr_t *self, uint64_t offs, const uint16_t *data, uint32_t flags);
typedef ssize_t (*proto_write_32_fp) (smpr_t *self, uint64_t offs, const uint32_t *data, uint32_t flags);
typedef ssize_t (*proto_write_64_fp) (smpr_t *self, uint64_t offs, const uint64_t *data, uint32_t flags);
typedef ssize_t (*proto_write_16_fp) (smpr_t *self, size_t size_offs, uint64_t offs, const uint16_t *data);
typedef ssize_t (*proto_write_32_fp) (smpr_t *self, size_t size_offs, uint64_t offs, const uint32_t *data);
typedef ssize_t (*proto_write_64_fp) (smpr_t *self, size_t size_offs, uint64_t offs, const uint64_t *data);
/* Read data block from protocol, size in bytes */
typedef ssize_t (*proto_read_block_fp) (smpr_t *self, uint64_t offs, size_t size, uint32_t *data, uint32_t flags);
typedef ssize_t (*proto_read_block_fp) (smpr_t *self, size_t size_offs, uint64_t offs, size_t size, uint32_t *data);
/* Write data block from protocol, size in bytes */
typedef ssize_t (*proto_write_block_fp) (smpr_t *self, uint64_t offs, size_t size, const uint32_t *data, uint32_t flags);
typedef ssize_t (*proto_write_block_fp) (smpr_t *self, size_t size_offs, uint64_t offs, size_t size, const uint32_t *data);
/* Read data block via DMA from protocol, size in bytes */
typedef ssize_t (*proto_read_dma_fp) (smpr_t *self, uint64_t offs, size_t size, uint32_t *data, uint32_t flags);
typedef ssize_t (*proto_read_dma_fp) (smpr_t *self, size_t size_offs, uint64_t offs, size_t size, uint32_t *data);
/* Write data block via DMA from protocol, size in bytes */
typedef ssize_t (*proto_write_dma_fp) (smpr_t *self, uint64_t offs, size_t size, const uint32_t *data, uint32_t flags);
typedef ssize_t (*proto_write_dma_fp) (smpr_t *self, size_t size_offs, uint64_t offs, size_t size, const uint32_t *data);
typedef struct {
const char *proto_name; /* Protocol name */
proto_open_fp proto_open; /* Open protocol */
proto_release_fp proto_release; /* Release protocol */
proto_read_16_fp proto_read_16; /* Read 16-bit data */
......@@ -71,7 +63,8 @@ typedef struct {
/***************** Our methods *****************/
/* Creates a new instance of the Low-level I/O */
smpr_t * smpr_new (char *name, smio_t *parent, smpr_type_e type, int verbose);
smpr_t * smpr_new (char *name, smio_t *parent, const smpr_proto_ops_t *reg_ops,
int verbose);
/* Destroy an instance of the Low-level I/O */
smpr_err_e smpr_destroy (smpr_t **self_p);
/* Register Specific Protocol operations to smpr instance */
......@@ -82,6 +75,10 @@ void *smpr_get_handler (smpr_t *self);
void *smpr_unset_handler (smpr_t *self);
/* Get parent handler */
smio_t *smpr_get_parent (smpr_t *self);
/* Get ops */
const smpr_proto_ops_t *smpr_get_ops (smpr_t *self);
/* Get protocol name */
const char *smpr_get_ops_name (smpr_t *self);
/************************************************************/
/***************** Thsafe generic methods API ***************/
......@@ -92,21 +89,21 @@ int smpr_open (smpr_t *self, uint64_t base, void *args);
/* Release protocol */
int smpr_release (smpr_t *self);
/* Read data from protocol */
ssize_t smpr_read_16 (smpr_t *self, uint64_t offs, uint16_t *data, uint32_t flags);
ssize_t smpr_read_32 (smpr_t *self, uint64_t offs, uint32_t *data, uint32_t flags);
ssize_t smpr_read_64 (smpr_t *self, uint64_t offs, uint64_t *data, uint32_t flags);
ssize_t smpr_read_16 (smpr_t *self, size_t size_offs, uint64_t offs, uint16_t *data);
ssize_t smpr_read_32 (smpr_t *self, size_t size_offs, uint64_t offs, uint32_t *data);
ssize_t smpr_read_64 (smpr_t *self, size_t size_offs, uint64_t offs, uint64_t *data);
/* Write data to protocol */
ssize_t smpr_write_16 (smpr_t *self, uint64_t offs, const uint16_t *data, uint32_t flags);
ssize_t smpr_write_32 (smpr_t *self, uint64_t offs, const uint32_t *data, uint32_t flags);
ssize_t smpr_write_64 (smpr_t *self, uint64_t offs, const uint64_t *data, uint32_t flags);
ssize_t smpr_write_16 (smpr_t *self, size_t size_offs, uint64_t offs, const uint16_t *data);
ssize_t smpr_write_32 (smpr_t *self, size_t size_offs, uint64_t offs, const uint32_t *data);
ssize_t smpr_write_64 (smpr_t *self, size_t size_offs, uint64_t offs, const uint64_t *data);
/* Read data block from protocol, size in bytes */
ssize_t smpr_read_block (smpr_t *self, uint64_t offs, size_t size, uint32_t *data, uint32_t flags);
ssize_t smpr_read_block (smpr_t *self, size_t size_offs, uint64_t offs, size_t size, uint32_t *data);
/* Write data block from protocol, size in bytes */
ssize_t smpr_write_block (smpr_t *self, uint64_t offs, size_t size, uint32_t *data, uint32_t flags);
ssize_t smpr_write_block (smpr_t *self, size_t size_offs, uint64_t offs, size_t size, uint32_t *data);
/* Read data block via DMA from protocol, size in bytes */
ssize_t smpr_read_dma (smpr_t *self, uint64_t offs, size_t size, uint32_t *data, uint32_t flags);
ssize_t smpr_read_dma (smpr_t *self, size_t size_offs, uint64_t offs, size_t size, uint32_t *data);
/* Write data block via DMA from protocol, size in bytes */
ssize_t smpr_write_dma (smpr_t *self, uint64_t offs, size_t size, uint32_t *data, uint32_t flags);
ssize_t smpr_write_dma (smpr_t *self, size_t size_offs, uint64_t offs, size_t size, uint32_t *data);
#ifdef __cplusplus
}
......
......@@ -12,10 +12,7 @@
extern "C" {
#endif
/* For use by llio_t general structure */
extern const smpr_proto_ops_t smpr_proto_ops_bsmp;
/***************** SMPR proto BSMP methods ************************************/
/***************** SMPR proto BSMP methods **********************/
/* Read/Write to RFFE vars by ID */
smpr_err_e smpr_bsmp_read_var_by_id (smpr_t *self, uint32_t id, uint8_t *data,
......@@ -29,6 +26,16 @@ smpr_err_e smpr_bsmp_func_exec_by_id (smpr_t *self, uint32_t id, uint8_t *write_
smpr_err_e smpr_bsmp_read_curve_by_id (smpr_t *self, uint32_t id, uint8_t *read_data,
size_t size, size_t *valid_bytes);
/************************* Our Methods **************************/
/* Creates a new instance of the proto_bsmp */
smpr_bsmp_t *smpr_bsmp_new ();
/* Destroy an instance of the bsmp */
smpr_err_e smpr_bsmp_destroy (smpr_bsmp_t **self_p);
/* Get BSMP operations */
const smpr_proto_ops_t *smpr_bsmp_get_ops (smpr_bsmp_t *self);
#ifdef __cplusplus
}
#endif
......
......@@ -24,8 +24,23 @@ typedef enum {
I2C_MODE_REP_START, /* Repetitive start mode */
} i2c_mode_e;
/* For use by llio_t general structure */
extern const smpr_proto_ops_t smpr_proto_ops_i2c;
/* Creates a new instance of the proto_i2c */
smpr_i2c_t *smpr_i2c_new (uint32_t rep_start, uint32_t addr);
/* Destroy an instance of the i2c */
smpr_err_e smpr_i2c_destroy (smpr_i2c_t **self_p);
/* Set I2C rep_start parameter */
smpr_err_e smpr_i2c_set_rep_start (smpr_i2c_t *self, uint32_t rep_start);
/* Get I2C rep_start parameter */
uint32_t smpr_i2c_get_rep_start (smpr_i2c_t *self);
/* Set I2C addr parameter */
smpr_err_e smpr_i2c_set_addr (smpr_i2c_t *self, uint32_t addr);
/* Get I2C addr parameter */
uint32_t smpr_i2c_get_addr (smpr_i2c_t *self);
/* Get I2C operations */
const smpr_proto_ops_t *smpr_i2c_get_ops (smpr_i2c_t *self);
#ifdef __cplusplus
}
......
......@@ -26,8 +26,25 @@ typedef enum {
SPI_MODE_WRITE_READ
} spi_mode_e;
/* For use by llio_t general structure */
extern const smpr_proto_ops_t smpr_proto_ops_spi;
/************************* Our Methods **************************/
/* Creates a new instance of the proto_spi */
smpr_spi_t *smpr_spi_new (uint32_t ss, uint32_t addr_msb);
/* Destroy an instance of the spi */
smpr_err_e smpr_spi_destroy (smpr_spi_t **self_p);
/* Set SPI SS parameter */
smpr_err_e smpr_spi_set_ss (smpr_spi_t *self, uint32_t ss);
/* Get SPI SS parameter */
uint32_t smpr_spi_get_ss (smpr_spi_t *self);
/* Get SPI addr_msb parameter */
smpr_err_e smpr_spi_set_addr_msb (smpr_spi_t *self, uint32_t addr_msb);
/* Get SPI addr_msb parameter */
uint32_t smpr_spi_get_addr_msb (smpr_spi_t *self);
/* Get SPI operations */
const smpr_proto_ops_t *smpr_spi_get_ops (smpr_spi_t *self);
#ifdef __cplusplus
}
......
......@@ -293,6 +293,7 @@ int main (int argc, char *argv[])
}
devio_err_e err = DEVIO_SUCCESS;
const llio_ops_t *llio_ops = NULL;
/* Check Dev_type */
switch (llio_type) {
case ETH_DEV:
......@@ -312,6 +313,9 @@ int main (int argc, char *argv[])
ASSERT_TEST (err == DEVIO_SUCCESS, "Could not get dev_entry from config file",
err_exit);
}
/* Get LLIO operations */
llio_ops = &llio_ops_eth;
break;
case PCIE_DEV:
......@@ -355,10 +359,13 @@ int main (int argc, char *argv[])
* on a larger system relying on systemd spawning, for instance */
ASSERT_TEST (fe_smio_id == 0, "Invalid Dev_id for PCIE_DEV. Only "
"odd device IDs are available", err_exit, 0);
llio_ops = &llio_ops_pcie;
break;
default:
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[ebpm] Invalid Dev_type. Exiting ...\n");
llio_ops = NULL;
goto err_exit;
}
......@@ -462,7 +469,7 @@ int main (int argc, char *argv[])
char devio_service_str [DEVIO_SERVICE_LEN];
snprintf (devio_service_str, DEVIO_SERVICE_LEN-1, "BPM%u:DEVIO", dev_id);
devio_service_str [DEVIO_SERVICE_LEN-1] = '\0'; /* Just in case ... */
devio_t *devio = devio_new (devio_service_str, dev_id, dev_entry, llio_type,
devio_t *devio = devio_new (devio_service_str, dev_id, dev_entry, llio_ops,
broker_endp, verbose, devio_log_filename);
ASSERT_ALLOC (devio, err_devio_alloc);
......
......@@ -153,23 +153,23 @@ static devio_sig_handler_t devio_sigchld_handler =
/* Creates a new instance of Device Information */
devio_t * devio_new (char *name, uint32_t id, char *endpoint_dev,
llio_type_e type, char *endpoint_broker, int verbose,
const llio_ops_t *reg_ops, char *endpoint_broker, int verbose,
const char *log_file_name)
{
assert (name);
assert (endpoint_dev);
assert (reg_ops);
assert (endpoint_broker);
/* Set logfile available for all dev_mngr and dev_io instances.
* We accept NULL as a parameter, meaning to suppress all messages */
errhand_set_log (log_file_name, DEVIO_DFLT_LOG_MODE);
char *dev_type_c = llio_type_to_str (type);
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io_core] Spawing DEVIO worker"
" with exported service %s, for a %s device \n\tlocated on %s,"
" broker address %s, with logfile on %s ...\n", name, dev_type_c,
" broker address %s, with logfile on %s ...\n", name,
(reg_ops->name == NULL) ? "NULL" : reg_ops->name,
endpoint_dev, endpoint_broker, (log_file_name == NULL) ? "NULL" : log_file_name);
free (dev_type_c);
/* Print Software info */
DBE_DEBUG (DBG_DEV_IO | DBG_LVL_INFO, "[dev_io_core] BPM Device I/O version %s,"
......@@ -253,7 +253,7 @@ devio_t * devio_new (char *name, uint32_t id, char *endpoint_dev,
ASSERT_ALLOC(llio_name, err_llio_name_alloc);
strcat (llio_name, name);
strcat (llio_name, LLIO_STR);
self->llio = llio_new (llio_name, endpoint_dev, type,
self->llio = llio_new (llio_name, endpoint_dev, reg_ops,
verbose);
ASSERT_ALLOC(self->llio, err_llio_alloc);
......@@ -281,7 +281,7 @@ devio_t * devio_new (char *name, uint32_t id, char *endpoint_dev,
/* Create SDB. If the device does not support SDB, this will fail.
* So, avoid creating SDB in this case, for now, as some unsupported
* endpoints do not have timeout implemented just yet */
if (llio_get_type (self->llio) == PCIE_DEV) {
if (streq (llio_get_ops_name (self->llio), "PCIE")) {
err = sdbfs_dev_create (self->sdbfs);
ASSERT_TEST (err == 0, "Could not create SDBFS",
err_sdbfs_create, DEVIO_ERR_SMIO_DO_OP);
......@@ -323,7 +323,7 @@ err_disp_table_thsafe_ops_alloc:
err_sm_io_cfg_h_alloc:
zhashx_destroy (&self->sm_io_h);
err_sm_io_h_alloc:
if (llio_get_type (self->llio) == PCIE_DEV) {
if (streq (llio_get_ops_name (self->llio), "PCIE")) {
sdbfs_dev_destroy (self->sdbfs);
}
err_sdbfs_create:
......@@ -474,7 +474,7 @@ devio_err_e devio_print_info (devio_t *self)
devio_err_e err = DEVIO_SUCCESS;
/* FIXME: Only valid for PCIe devices */
ASSERT_TEST (llio_get_type (self->llio) == PCIE_DEV,
ASSERT_TEST (streq (llio_get_ops_name (self->llio), "PCIE"),
"SDB is only supported for PCIe devices",
err_sdb_not_supp, DEVIO_ERR_FUNC_NOT_IMPL);
......@@ -989,7 +989,7 @@ static devio_err_e _devio_register_all_sm_raw (devio_t *self)
uint32_t smio_id = 0;
/* FIXME: Only valid for PCIe devices */
ASSERT_TEST (llio_get_type (self->llio) == PCIE_DEV,
ASSERT_TEST (streq (llio_get_ops_name (self->llio), "PCIE"),
"SDB is only supported for PCIe devices",
err_sdb_not_supp, DEVIO_ERR_FUNC_NOT_IMPL);
......
......@@ -87,6 +87,13 @@ char *hutils_concat_strings_no_sep (const char *str1, const char* str2);
char *hutils_concat_strings3 (const char *str1, const char* str2,
const char* str3, char sep);
/* Calculates necessary padding so that a given value is a multiple of a given
* alignment */
uint32_t hutils_calculate_padding(uint32_t value, uint32_t alignment);
/* Aligns a given value to a given alignment */
uint32_t hutils_align_value(uint32_t value, uint32_t alignment);
/* Spawns (fork and exec) a new process. Returns, for the parent process, -1
* in case of error and child's PID (> 0) if success. For the child process,
* returns -1 in case of error and 0 in case of success */
......
......@@ -177,6 +177,24 @@ char *hutils_concat_strings3 (const char *str1, const char* str2,
return _hutils_concat_strings_raw (str1, str2, str3, true, sep);
}
/*******************************************************************/
/***************** Byte manipulation functions ********************/
/*******************************************************************/
uint32_t hutils_calculate_padding(uint32_t value, uint32_t alignment)
{
uint32_t exceeded = value % alignment;
uint32_t remaining = alignment - exceeded;
uint32_t padding = remaining % alignment;
return padding;
}
uint32_t hutils_align_value(uint32_t value, uint32_t alignment)
{
return value + hutils_calculate_padding(value, alignment);
}
/*******************************************************************/
/***************** System Fork/Exec functions *********************/
/*******************************************************************/
......@@ -502,4 +520,3 @@ err_hash_item_alloc:
err_cfg_exit:
return err;
}
......@@ -36,6 +36,9 @@ typedef ssize_t (*write_dma_fp)(llio_t *self, uint64_t offs, size_t size, uint32
/* typedef int (*read_info_fp)(struct _llio_t *self, struct _llio_dev_info_t *dev_info); moved to dev_io */
typedef struct {
const char *name; /* LLIO device name */
/* Operations */
open_fp open; /* Open device */
release_fp release; /* Release device */
read_16_fp read_16; /* Read 16-bit data */
......@@ -60,7 +63,7 @@ typedef struct {
/************************************************************/
/* Creates a new instance of the Low-level I/O */
llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose);
llio_t * llio_new (char *name, char *endpoint, const llio_ops_t *reg_ops, int verbose);
/* Destroy an instance of the Low-level I/O */
llio_err_e llio_destroy (llio_t **self_p);
......@@ -83,7 +86,7 @@ llio_err_e llio_set_dev_handler (llio_t *self, void *dev_handler);
/* Get dev handler */
void *llio_get_dev_handler (llio_t *self);
/* Get type */
llio_type_e llio_get_type (llio_t *self);
const char *llio_get_ops_name (llio_t *self);
/* Set SDB prefix ADDR */
llio_err_e llio_set_sdb_prefix_addr (llio_t *self, uint64_t sdb_prefix_addr);
/* Get SDB prefix ADDR */
......
......@@ -32,32 +32,29 @@
/* LLIO class object */
struct _llio_t {
llio_type_e type; /* Device type (PCIe, Ethnernet, or other) */
void *dev_handler; /* Generic pointer to a device handler. This
must be cast to a specific type by the
devices functions */
char *name; /* Identification of this llio instance */
int verbose; /* Print activity to stdout */
uint64_t sdb_prefix_addr; /* SDB prefix address. Used to read/write to the
uint64_t sdb_prefix_addr; /* SDB prefix address. Used to read/write to the
SDB address space. To be set by the specific ops */
/* Endpoint to connect to */
llio_endpoint_t *endpoint;
/* SDB device info */
/* struct _llio_dev_info_t *dev_info; Moved to dev_io */
/* Device operations */
const llio_ops_t *ops;
};
/* Register Low-level operations to llio instance. Helpper function */
static llio_err_e _llio_register_ops (llio_type_e type, const llio_ops_t **llio_ops);
static llio_err_e _llio_register_ops (const llio_ops_t **ops, const llio_ops_t *reg_ops);
/* Unregister Low-level operations to llio instance. Helpper function */
static llio_err_e _llio_unregister_ops (const llio_ops_t **ops);
/* Get open endpoint status */
static bool _llio_get_endpoint_open (llio_t *self);
/* Creates a new instance of the Low-level I/O */
llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose)
llio_t * llio_new (char *name, char *endpoint, const llio_ops_t *reg_ops, int verbose)
{
assert (name);
assert (endpoint);
......@@ -66,7 +63,6 @@ llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose)
ASSERT_ALLOC(self, err_self_alloc);
/* Initialize Low-level IO type */
self->type = type;
self->dev_handler = NULL; /* This is set by the device functions */
self->name = strdup (name);
ASSERT_ALLOC(self->name, err_name_alloc);
......@@ -86,12 +82,9 @@ llio_t * llio_new (char *name, char *endpoint, llio_type_e type, int verbose)
ASSERT_ALLOC(self->dev_info, err_dev_info_alloc); Moved to dev_io */
/* Initilialize llio_ops */
/* self->ops = (llio_ops_t *) zmalloc (sizeof *self->ops); */
/* ASSERT_ALLOC(self->ops, err_ops_alloc); */
/* Nullify every ops field to indicate a non-implemented function */