pp-instance.h 6.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef __PPSI_PP_INSTANCE_H__
#define __PPSI_PP_INSTANCE_H__

/*
 * The "instance structure is the most important object in ppsi: is is
 * now part of a separate header because ppsi.h must refer to it, and
 * to diagnostic macros, but also diag-macros.h needs to look at
 * ppi->flags.
 */
#ifndef __PPSI_PPSI_H__
#warning "Please include <ppsi/ppsi.h>, don't refer to pp-instance.h"
#endif

/*
 * Runtime options. Default values can be overridden by command line.
 */
struct pp_runtime_opts {
	ClockQuality clock_quality;
	Integer32 ttl;
20
	int flags;		/* see below */
21 22 23
	Integer16 ap, ai;
	Integer16 s;
	Integer8 announce_intvl;
24 25 26 27
	int sync_intvl;
	int prio1;
	int prio2;
	int domain_number;
28 29
	void *arch_opts;
};
30

31 32 33 34 35 36 37 38 39 40 41 42 43
/*
 * Flags for the above structure
 */
#define PP_FLAG_NO_ADJUST  0x01
/* I'd love to use inlines, but we still miss some structure at this point*/
#define pp_can_adjust(ppi)      (!(OPTS(ppi)->flags & PP_FLAG_NO_ADJUST))

/* slave_only:1, -- moved to ppi, no more global */
/* master_only:1, -- moved to ppi, no more global */
/* ethernet_mode:1, -- moved to ppi, no more global */



44 45
/* We need a globally-accessible structure with preset defaults */
extern struct pp_runtime_opts __pp_default_rt_opts;
46 47

/*
48
 * Communication channel. Is the abstraction of a unix socket, so that
49 50 51 52 53 54 55 56 57 58 59 60
 * this struct is platform independent
 */
struct pp_channel {
	union {
		int fd;		/* Posix wants fid descriptor */
		void *custom;	/* Other archs want other stuff */
	};
	void *arch_data;	/* Other arch-private info, if any */
	unsigned char addr[6];	/* Our own MAC address */
	int pkt_present;
};

61

62
/*
Aurelio Colosimo's avatar
Aurelio Colosimo committed
63 64
 * Foreign master record. Used to manage Foreign masters. In the specific
 * it is called foreignMasterDS, see 9.3.2.4
65 66
 */
struct pp_frgn_master {
67
	PortIdentity port_id;	/* used to identify old/new masters */
68 69

	/* We don't need all fields of the following ones */
70 71 72 73 74 75 76 77 78
	MsgAnnounce ann;
	MsgHeader hdr;
};

/*
 * Servo. Structs which contain filters for delay average computation. They
 * are used in servo.c src, where specific function for time setting of the
 * machine are implemented.
 *
79
 * pp_avg_fltr: It is a variable cutoff/delay low-pass, infinite impulse
80
 * response (IIR) filter. The meanPathDelay filter has the difference equation:
81 82 83
 * s*y[n] - (s-1)*y[n-1] = x[n]/2 + x[n-1]/2,
 * where increasing the stiffness (s) lowers the cutoff and increases the delay.
 */
84
struct pp_avg_fltr {
85 86 87
	int64_t m; /* magnitude */
	int64_t y;
	int64_t s_exp;
88 89 90
};

struct pp_servo {
91 92
	struct pp_time m_to_s_dly;
	struct pp_time s_to_m_dly;
93
	long long obs_drift;
94
	struct pp_avg_fltr mpd_fltr;
95 96
};

97
enum { /* The two sockets. They are called "net path" for historical reasons */
98 99 100 101 102
	PP_NP_GEN =	0,
	PP_NP_EVT,
	__NR_PP_NP,
};

103 104
/*
 * Struct containg the result of ppsi.conf parsing: one for each link
105
 * (see lib/conf.c). Actually, protocol and role are in the main ppi.
106 107
 */
struct pp_instance_cfg {
108
	char port_name[16];
109
	char iface_name[16];
110 111
	int ext;   /* 0: none, 1: whiterabbit. 2: HA */
	int mech;   /* 0: E2E, 1: P2P */
112 113
};

114 115 116 117 118
/*
 * Structure for the individual ppsi link
 */
struct pp_instance {
	int state;
119
	int next_state, next_delay, is_new_state; /* set by state processing */
120
	struct pp_state_table_item *current_state_item;
121 122
	void *arch_data;		/* if arch needs it */
	void *ext_data;			/* if protocol ext needs it */
123
	unsigned long d_flags;		/* diagnostics, ppi-specific flags */
124 125
	unsigned char flags;		/* protocol flags (see below) */
	int	role,			/* same as in config file */
126 127
		proto,			/* same as in config file */
		mech;			/* same as in config file */
128

129 130 131
	/* Pointer to global instance owning this pp_instance*/
	struct pp_globals *glbs;

132 133 134 135 136
	/* Operations that may be different in each instance */
	struct pp_network_operations *n_ops;
	struct pp_time_operations *t_ops;

	/*
137 138 139
	 * The buffer for this fsm are allocated. Then we need two
	 * extra pointer to track separately the frame and payload.
	 * So send/recv use the frame, pack/unpack use the payload.
140
	 */
141
	void *__tx_buffer, *__rx_buffer;
142 143 144
	void *tx_frame, *rx_frame, *tx_ptp, *rx_ptp;

	/* The net_path used to be allocated separately, but there's no need */
145
	struct pp_channel ch[__NR_PP_NP];	/* general and event ch */
146
	Integer32 mcast_addr[2];		/* only ipv4/udp */
147
	int tx_offset, rx_offset;		/* ptp payload vs send/recv */
148 149
	unsigned char peer[6];	/* Our peer's MAC address */
	uint16_t peer_vid;	/* Our peer's VID (for PROTO_VLAN) */
150

151
	/* Times, for the various offset computations */
152
	struct pp_time t1, t2, t3, t4, t5, t6;		/* *the* stamps */
153
	uint64_t syncCF;				/* transp. clocks */
154
	struct pp_time last_rcv_time, last_snt_time;	/* two temporaries */
155

156 157 158 159 160 161 162
	/* Page 85: each port shall maintain an implementation-specific
	 * foreignMasterDS data set for the purposes of qualifying Announce
	 * messages */
	UInteger16 frgn_rec_num;
	Integer16  frgn_rec_best;
	struct pp_frgn_master frgn_master[PP_NR_FOREIGN_RECORDS];

163
	DSPort *portDS;				/* page 72 */
164

165 166 167 168 169
	unsigned long timeouts[__PP_TO_ARRAY_SIZE];
	UInteger16 recv_sync_sequence_id;

	UInteger16 sent_seq[__PP_NR_MESSAGES_TYPES]; /* last sent this type */
	MsgHeader received_ptp_header;
170

171 172
	char *iface_name; /* for direct actions on hardware */
	char *port_name; /* for diagnostics, mainly */
173
	int port_idx;
174 175 176
	int vlans_array_len; /* those looking at shared mem must check */
	int vlans[CONFIG_VLAN_ARRAY_SIZE];
	int nvlans; /* according to configuration */
177
	struct pp_instance_cfg cfg;
178 179 180

	unsigned long ptp_tx_count;
	unsigned long ptp_rx_count;
181
};
182 183 184
/* The following things used to be bit fields. Other flags are now enums */
#define PPI_FLAG_FROM_CURRENT_PARENT	0x01
#define PPI_FLAG_WAITING_FOR_F_UP	0x02
185 186
#define PPI_FLAG_WAITING_FOR_RF_UP	0x04
#define PPI_FLAGS_WAITING		0x06 /* both of the above */
187

188 189 190 191
struct pp_globals_cfg {
	int cfg_items;			/* Remember how many we parsed */
	int cur_ppi_n;	/* Remember which instance we are configuring */
};
192

193 194 195 196 197
/*
 * Structure for the multi-port ppsi instance.
 */
struct pp_globals {
	struct pp_instance *pp_instances;
198 199

	struct pp_servo *servo;
200

201 202 203
	/* Real time options */
	struct pp_runtime_opts *rt_opts;

204 205 206 207 208 209
	/* Data sets */
	DSDefault *defaultDS;			/* page 65 */
	DSCurrent *currentDS;			/* page 67 */
	DSParent *parentDS;			/* page 68 */
	DSTimeProperties *timePropertiesDS;	/* page 70 */

210 211 212 213
	/* Index of the pp_instance receiving the "Ebest" clock */
	int ebest_idx;
	int ebest_updated; /* set to 1 when ebest_idx changes */

214 215
	int nlinks;
	int max_links;
216
	struct pp_globals_cfg cfg;
217

218 219
	int rxdrop, txdrop;		/* fault injection, per thousand */

220
	void *arch_data;		/* if arch needs it */
221
	void *global_ext_data;		/* if protocol ext needs it */
222 223 224
	/* FIXME Here include all is common to many interfaces */
};

225
#endif /* __PPSI_PP_INSTANCE_H__ */