Commit 6a7bd674 authored by Jean-Claude BAU's avatar Jean-Claude BAU

In arch-wrs, create symbolic links to access libwr includes.

This modification avoids duplication of files.
parent b65420ce
......@@ -109,7 +109,7 @@ $(TARGET).o: $(OBJ-y)
$(OBJ-y): .config $(wildcard include/ppsi/*.h)
# Finally, "make clean" is expected to work
clean:
clean::
rm -f $$(find . -name '*.[oa]' ! -path './scripts/kconfig/*') *.bin $(TARGET) *~ $(TARGET).map*
distclean: clean
......
......@@ -8,24 +8,45 @@ CFLAGS += -Itools
# Prevent a warning for a missing prototype in pp_printf, bug since ever
ARCH_PP_PRINTF_CFLAGS += -include ../$A/include/strnlen.h
OBJ-y += $A/wrs-startup.o \
$A/hal_minirpc.o \
$A/main-loop.o \
$A/wrs-io.o \
$A/wrs-conf.o \
$A/wrs-calibration.o \
$A/wrs-port.o \
$A/wrs-ipcserver.o \
$A/shmem.o \
$A/util.o \
lib/cmdline.o \
lib/conf.o \
lib/libc-functions.o \
lib/dump-funcs.o \
lib/drop.o \
lib/assert.o \
lib/div64.o \
lib/time-arith.o
arch-spec-c = $A/wrs-startup.c \
$A/hal_minirpc.c \
$A/main-loop.c \
$A/wrs-io.c \
$A/wrs-conf.c \
$A/wrs-calibration.c \
$A/wrs-port.c \
$A/wrs-ipcserver.c \
$A/shmem.c \
$A/util.c \
lib/cmdline.c \
lib/conf.c \
lib/libc-functions.c \
lib/dump-funcs.c \
lib/drop.c \
lib/assert.c \
lib/div64.c \
lib/time-arith.c
arch-spec-o = $(patsubst %.c,%.o,$(arch-spec-c))
OBJ-y += $(arch-spec-o)
# build symbolic links for libwr
hal_headers = hal_shmem.h \
generic_fsm.h\
sfp_lib.h\
util.h\
shmem.h \
timeout.h
hal_headers_in_ppsi= $(addprefix $A/include/libwr/,$(hal_headers))
$(arch-spec-o) : $(hal_headers_in_ppsi)
$(hal_headers_in_ppsi):
@f=$(notdir $@); \
echo "Creating symbolic link to $$f";\
ln -sf ../../../../libwr/include/libwr/$$f $@
export size_db_file:=size_wrs_db.txt
export size_info_file:=size_wrs_info.txt
......@@ -51,6 +72,9 @@ OBJ-y += $(MINIPC_LIB)
all: $(TARGET)
clean::
rm -f $(hal_headers_in_ppsi)
# to build the target, we need -lstd again, in case we call functions that
# were not selected yet (e.g., pp_init_globals() ).
$(TARGET): $(TARGET).o
......
#ifndef __LIBWR_HAL_SHMEM_H__
#define __LIBWR_HAL_SHMEM_H__
#include <hal_exports.h>
#include <libwr/sfp_lib.h>
#include <string.h>
/* Port state machine states */
typedef enum {
HAL_PORT_STATE_INIT=0,
HAL_PORT_STATE_DISABLED,
HAL_PORT_STATE_LINK_DOWN,
HAL_PORT_STATE_LINK_UP,
} halPortState_t;
/* Read temperature from SFPs */
#define READ_SFP_DIAG_ENABLE 1
#define READ_SFP_DIAG_DISABLE 0
/* Monitor port in SNMP */
#define HAL_PORT_MONITOR_ENABLE 1
#define HAL_PORT_MONITOR_DISABLE 2
#define DEFAULT_T2_PHASE_TRANS 0
#define DEFAULT_T4_PHASE_TRANS 0
/* Port delay calibration parameters */
typedef struct hal_port_calibration {
/* PHY delay measurement parameters for PHYs which require
external calibration (i.e. with the feedback network. */
/* minimum possible delay introduced by the PHY. Expressed as time
(in picoseconds) between the beginning of the symbol on the serial input
and the rising edge of the RX clock at which the deserialized word is
available at the parallel output of the PHY. */
uint32_t phy_rx_min;
/* the same set of parameters, but for the TX path of the PHY */
uint32_t phy_tx_min;
/* Current PHY (clock-to-serial-symbol) TX and RX delays, in ps */
uint32_t delta_tx_phy;
uint32_t delta_rx_phy;
/* bit slide expresse in picos */
uint32_t bitslide_ps;
/* Current board routing delays (between the DDMTD inputs to
the PHY clock inputs/outputs), in picoseconds */
uint32_t delta_tx_board;
uint32_t delta_rx_board;
/* When non-zero: RX path is calibrated (delta_*_rx contain valid values) */
int rx_calibrated;
/* When non-zero: TX path is calibrated */
int tx_calibrated;
struct shw_sfp_caldata sfp;
struct shw_sfp_header sfp_header_raw;
struct shw_sfp_dom sfp_dom_raw;
} hal_port_calibration_t;
/* States used by the generic FSM */
typedef struct {
int state;
int nextState;
} halPortFsmState_t;
/* Internal port state structure */
struct hal_port_state {
int in_use; /* non-zero: allocated */
char name[16]; /* linux i/f name */
uint8_t hw_addr[6]; /* MAC addr */
int hw_index; /* ioctl() hw index : 0..n */
int fd; /* file descriptor for ioctls() */
int hw_addr_auto;
/* port FSM state (HAL_PORT_STATE_xxxx) */
halPortFsmState_t portStates;
int fiber_index;/* fiber type, used to get alpha for SFP frequency */
int locked; /* 1: PLL is locked to this port */
/* calibration data */
hal_port_calibration_t calib;
/* current DMTD loopback phase (ps) and whether is it valid or not */
uint32_t phase_val;
int phase_val_valid;
int tx_cal_pending, rx_cal_pending;
int lock_state; /* locking FSM state */
uint32_t clock_period; /*reference lock period in picoseconds*/
/* approximate DMTD phase value (on slave port) at which RX timestamp
* (T2) counter transistion occurs (picoseconds) */
uint32_t t2_phase_transition;
/* approximate phase value (on master port) at which RX timestamp (T4)
* counter transistion occurs (picoseconds) */
uint32_t t4_phase_transition;
uint32_t ep_base;/* Endpoint's base address */
/* whether SFP has diagnostic Monitoring capability */
int has_sfp_diag;
/* True if SFP is inserted */
int sfpPresent;
/* whether the port shall be monitored by SNMP */
int monitor;
/* PPSi instance information */
int portMode; // Instance state
int synchronized; // <>0 if port is synchronized
int portInfoUpdated; // Set to 1 when updated
/* Events to process */
int evt_reset; /* Set if a reset is requested */
int evt_lock; /* Set if the ptracker must be activated*/
int evt_linkUp; /* Set if link is up ( driver call */
/* Low phase drift calibration data */
void *lpdc;
/* Pll FSM */
halPortFsmState_t pllStates;
};
struct hal_temp_sensors {
int fpga; /* IC19 */
int pll; /* IC18 */
int psl; /* IC20 Power Supply Left (PSL) */
int psr; /* IC17 Power Supply Right (PSR) */
};
/* This is the overall structure stored in shared memory */
#define HAL_SHMEM_VERSION 15 /* Add share memory state*/
typedef enum {
HAL_SHMEM_STATE_NOT_INITITALIZED=0,
HAL_SHMEM_STATE_INITITALIZING,
HAL_SHMEM_STATE_INITITALIZED
}halShmemState_t;
struct hal_shmem_header {
int nports;
int hal_mode;
halShmemState_t shmemState;
struct hal_port_state *ports;
struct hal_temp_sensors temp;
int read_sfp_diag;
};
static inline int get_port_state(struct hal_port_state *ps)
{
return ps->portStates.state;
}
static inline int state_up(struct hal_port_state *ps)
{
return get_port_state(ps) == HAL_PORT_STATE_LINK_UP;
}
static inline struct hal_port_state *hal_lookup_port(
struct hal_port_state *ports, int nports,
const char *name)
{
int i;
for (i = 0; i < nports; i++)
if (ports[i].in_use && (!strcmp(name, ports[i].name)))
return ports + i;
return NULL;
}
#endif /* __LIBWR_HAL_SHMEM_H__ */
../../../../libwr/include/libwr/hal_shmem.h
\ No newline at end of file
#ifndef __LIBWR_SHW_SFPLIB_H
#define __LIBWR_SHW_SFPLIB_H
/* note each led contains green and orange part */
#define SFP_LED_WRMODE1 (1 << 0)
#define SFP_LED_WRMODE2 (1 << 1)
#define SFP_LED_SYNCED (1 << 2)
#define SFP_TX_DISABLE (1 << 3)
#define shw_sfp_set_led_synced(num, status) \
shw_sfp_set_generic(num, status, SFP_LED_SYNCED)
#define shw_sfp_set_tx_disable(num, status) \
shw_sfp_set_generic(num, status, SFP_TX_DISABLE)
#define SFP_FLAG_CLASS_DATA (1 << 0)
#define SFP_FLAG_DEVICE_DATA (1 << 1)
#define SFP_FLAG_1GbE (1 << 2) /* SFP is 1GbE */
#define SFP_FLAG_IN_DB (1 << 3) /* SFP is present in data base */
#define SFP_SPEED_1Gb 0x0D /* Speed of SFP in 100MB/s. According to
* SFF-8472.PDF: By convention 1.25 Gb/s
* should be rounded up to 0Dh (13 in
* units of 100 MBd) for Ethernet
* 1000BASE-X. */
#define SFP_SPEED_1Gb_10 0x0A /* Unfortunatelly the above is not always true,
* e.g. Cisco copper SFP (MGBT1) says simply 10 and not 13.*/
#define SFP_DIAGNOSTIC_IMPLEMENTED (1 << 6) /* Digital diagnostic monitoring
implemented. "1" for compliance
with SFF-8472 */
#define SFP_ADDR_CHANGE_REQ (1 << 2) /* Bit 2 indicates whether or not it is
necessary for the host to perform an
address change sequence before
accessing information at 2-wire serial
address A2h. */
struct shw_sfp_caldata {
uint32_t flags;
/*
* Part number used to identify it. Serial number because we
* may specify per-specimen delays, but it is not used at this
* point in time
*/
char vendor_name[16];
char part_num[16];
char vendor_serial[16];
/* Callibration data */
double alpha;
int delta_tx_ps; /* "delta" of this SFP type WRT calibration type */
int delta_rx_ps;
/* wavelengths, used to get alpha from fiber type */
int tx_wl;
int rx_wl;
/* and link as a list */
struct shw_sfp_caldata *next;
};
struct shw_sfp_header {
uint8_t id;
uint8_t ext_id;
uint8_t connector;
uint8_t transciever[8];
uint8_t encoding;
uint8_t br_nom;
uint8_t reserved1;
uint8_t length1; /* Link length supported for 9/125 mm fiber (km) */
uint8_t length2; /* Link length supported for 9/125 mm fiber (100m) */
uint8_t length3; /* Link length supported for 50/125 mm fiber (10m) */
uint8_t length4; /* Link length supported for 62.5/125 mm fiber (10m) */
uint8_t length5; /* Link length supported for copper (1m) */
uint8_t length6; /* Link length supported on OM3 (1m) */
uint8_t vendor_name[16];
uint8_t reserved3; /* This is now a field named transceiver */
uint8_t vendor_oui[3];
uint8_t vendor_pn[16];
uint8_t vendor_rev[4];
uint8_t tx_wavelength[2];
uint8_t reserved4;
uint8_t cc_base;
/* extended ID fields start here */
uint8_t options[2];
uint8_t br_max;
uint8_t br_min;
uint8_t vendor_serial[16];
uint8_t date_code[8];
uint8_t diagnostic_monitoring_type;
uint8_t enhanced_options;
uint8_t sff_8472_compliance;
uint8_t cc_ext;
} __attribute__ ((packed));
struct shw_sfp_dom {
/* Treshold values, 0 - 55 */
uint8_t temp_high_alarm[2];
uint8_t temp_low_alarm[2];
uint8_t temp_high_warn[2];
uint8_t temp_low_warn[2];
uint8_t volt_high_alarm[2];
uint8_t volt_low_alarm[2];
uint8_t volt_high_warn[2];
uint8_t volt_low_warn[2];
uint8_t bias_high_alarm[2];
uint8_t bias_low_alarm[2];
uint8_t bias_high_warn[2];
uint8_t bias_low_warn[2];
uint8_t tx_pow_high_alarm[2];
uint8_t tx_pow_low_alarm[2];
uint8_t tx_pow_high_warn[2];
uint8_t tx_pow_low_warn[2];
uint8_t rx_pow_high_alarm[2];
uint8_t rx_pow_log_alarm[2];
uint8_t rx_power_high_warn[2];
uint8_t rx_power_low_warn[2];
uint8_t unalloc0[16];
/* Calibration data, 56-91 */
uint8_t cal_rx_pwr4[4];
uint8_t cal_rx_pwr3[4];
uint8_t cal_rx_pwr2[4];
uint8_t cal_rx_pwr1[4];
uint8_t cal_rx_pwr0[4];
uint8_t cal_tx_i_slope[2];
uint8_t cal_tx_i_offset[2];
uint8_t cal_tx_pow_slope[2];
uint8_t cal_tx_pow_offset[2];
uint8_t cal_T_slope[2];
uint8_t cal_T_offset[2];
uint8_t cal_V_slope[2];
uint8_t cal_V_offset[2];
/* Unallocated and checksum, 92-95 */
uint8_t cal_unalloc[3];
uint8_t CC_DMI;
/* Real Time Diagnostics, 96-111 */
uint8_t temp[2];
uint8_t vcc[2];
uint8_t tx_bias[2];
uint8_t tx_pow[2];
uint8_t rx_pow[2];
uint8_t rtd_unalloc0[4];
uint8_t OSCB;
uint8_t rtd_unalloc1;
/* Alarms and Warnings, 112 - 117 */
uint8_t alw[6];
/* Extended Module Control/Status bytes 118 - 119 */
uint8_t emcsb[2];
/* Vendor locations 120 - 127 */
uint8_t vendor_locations[8];
/* User data 128 - 247 */
uint8_t dom_user[120];
/* Vendor specific control function locations 248 - 255 */
uint8_t vendor_functions[8];
} __attribute__ ((packed));
/* Public API */
/*
* Scan all ports for plugged in SFP's. The return value is a bitmask
* of all the ports with detected SFP's (bits 0-17 are valid).
*/
uint32_t shw_sfp_module_scan(void);
/* Set/get the 4 GPIO's connected to PCA9554's for a particular SFP */
void shw_sfp_gpio_set(int num, uint8_t state);
uint8_t shw_sfp_gpio_get(int num);
static inline void shw_sfp_set_generic(int num, int status, int type)
{
uint8_t state;
state = shw_sfp_gpio_get(num);
if (status)
state |= type;
else
state &= ~type;
shw_sfp_gpio_set(num, state);
}
/* Load the db from dot-config to internal structures */
int shw_sfp_read_db(void);
/* Read and verify the header all at once. returns -1 on failure */
int shw_sfp_read_verify_header(int num, struct shw_sfp_header *head);
/* Read the SFP diagnostics page */
int shw_sfp_read_dom(int num, struct shw_sfp_dom *dom);
/* Update the SFP diagnostics page */
int shw_sfp_update_dom(int num, struct shw_sfp_dom *dom);
/* Decode and print the SFP real time diagnostics */
void shw_sfp_print_dom(struct shw_sfp_dom * dom);
/* Dump the SFP diagnostics page in hex */
void shw_sfp_dom_dump(struct shw_sfp_dom * dom);
/* return NULL if no data found */
struct shw_sfp_caldata *shw_sfp_get_cal_data(int num,
struct shw_sfp_header *head);
#endif /* __LIBWR_SHW_SFPLIB_H */
../../../../libwr/include/libwr/sfp_lib.h
\ No newline at end of file
/*
* This is the shared memory interface for multi-process cooperation
* within the whiterabbit switch. Everyone exports status information.
*/
#ifndef __WRS_SHM_H__
#define __WRS_SHM_H__
#include <stdint.h>
#include <stdio.h>
#define WRS_SHM_DEFAULT_PATH "/dev/shm"
#define WRS_SHM_FILE "wrs-shmem-%i"
#define WRS_SHM_MIN_SIZE (4*1024)
#define WRS_SHM_MAX_SIZE (512*1024)
/* Each process "name" (i.e. id) is added to the filename above */
enum wrs_shm_name {
wrs_shm_ptp,
wrs_shm_rtu,
wrs_shm_hal,
wrs_shm_vlan,
WRS_SHM_N_NAMES, /* must be last */
};
/* Each area starts with this process identifier */
struct wrs_shm_head {
void *mapbase; /* In writer's addr space (to track ptrs) */
char name[7 * sizeof(void *)];
unsigned long stamp; /* Last modified, w/ CLOCK_MONOTONIC */
unsigned long data_off; /* Where the structure lives */
int fd; /* So we can enlarge it using fd */
int pid; /* The current pid owning the area */
unsigned pidsequence; /* Each new pid must increments this */
unsigned sequence; /* If we need consistency, this is it. LSB bit
* informs whether shmem is locked already */
unsigned version; /* Version of the data structure */
const char *last_write_caller; /* Function of the last wrs_shm_write
* call */
int last_write_line; /* Line of the last wrs_shm_write call */
unsigned data_size; /* Size of it (for binary dumps) */
};
/* flags */
#define WRS_SHM_READ 0x0000
#define WRS_SHM_WRITE 0x0001
#define WRS_SHM_LOCKED 0x0002 /* at init time: writers locks, readers wait */
#define WRS_SHM_LOCK_MASK 0x0001
/* return values of wrs_shm_get_and_check */
#define WRS_SHM_OPEN_OK 0x0001
#define WRS_SHM_OPEN_FAILED 0x0001
#define WRS_SHM_WRONG_VERSION 0x0002
#define WRS_SHM_INCONSISTENT_DATA 0x0003
/* Set custom path for shmem */
void wrs_shm_set_path(char *new_path);
/* Allow to ignore the flag WRS_SHM_LOCKED
* If this flag is not ignored then function wrs_shm_get_and_check is not able
* to open shmem successfully due to lack of process running with the given pid
*/
void wrs_shm_ignore_flag_locked(int ignore_flag);
/* get vs. put, like in the kernel. Errors are in errno (see source) */
struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name,
unsigned long flags);
int wrs_shm_put(struct wrs_shm_head *head);
/* A reader may wait for the writer (polling on version field) */
void wrs_shm_wait(struct wrs_shm_head *head, int msec_step, int retries,
FILE *msg);
int wrs_shm_get_and_check(enum wrs_shm_name shm_name,
struct wrs_shm_head **head);
/* The writer can allocate structures that live in the area itself */
void *wrs_shm_alloc(struct wrs_shm_head *head, size_t size);
/* The reader can track writer's pointers, if they are in the area */
void *wrs_shm_follow(struct wrs_shm_head *head, void *ptr);
/* Before and after writing a chunk of data, act on sequence and stamp */
#define WRS_SHM_WRITE_BEGIN 1
#define WRS_SHM_WRITE_END 0
/* A helper to pass the name of a caller function and a line of the call */
#define wrs_shm_write(headptr, flags) wrs_shm_write_caller(headptr, flags, \
__func__, __LINE__)
extern void wrs_shm_write_caller(struct wrs_shm_head *head, int flags,
const char *caller, int line);
/* A reader can rely on the sequence number (in the <linux/seqlock.h> way) */
extern unsigned wrs_shm_seqbegin(struct wrs_shm_head *head);
extern int wrs_shm_seqretry(struct wrs_shm_head *head, unsigned start);
/* A reader can check wether information is current enough */
extern int wrs_shm_age(struct wrs_shm_head *head);
/* A reader can get the information pointer, for a specific version, or NULL */
extern void *wrs_shm_data(struct wrs_shm_head *head, unsigned version);
#endif /* __WRS_SHM_H__ */
../../../../libwr/include/libwr/shmem.h
\ No newline at end of file
#ifndef __LIBWR_HW_UTIL_H
#define __LIBWR_HW_UTIL_H
#include <stdio.h>
#include <inttypes.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#define atoidef(argc, argv, param_i, def) (argc > (param_i) ? \
atoi(argv[(param_i)]) : (def))
#define strtoldef(argc, argv, param_i, def) (argc > (param_i) ? \
strtol(argv[(param_i)], NULL, 0) : (def))
void shw_udelay_init(void);
void shw_udelay(uint32_t microseconds);
/* get monotonic number of useconds */
uint64_t get_monotonic_us(void);
/* get monotonic number of seconds */
time_t get_monotonic_sec(void);
/* Change endianess of the string, for example when accessing strings in
* the SoftPLL */
void strncpy_e(char *d, char *s, int len);
/* Create map */
void *create_map(unsigned long address, unsigned long size);
#endif /* __LIBWR_HW_UTIL_H */
../../../../libwr/include/libwr/util.h
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment