ptp4l: Allow per-port customized port defaults

this patch allows each port to maintain its own pod structure since it is only
used in ports. This will allow the user to configure any special settings per
port. It takes a copy of the default pod, and a future patch will allow the
configuration file to set per-port specific changes

-v2
* Minor change to fix merge with previous patch

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
master
Jacob Keller 2012-08-20 10:56:50 -07:00 committed by Richard Cochran
parent 733d4ccf9e
commit 7a69db2379
7 changed files with 10 additions and 14 deletions

View File

@ -210,8 +210,7 @@ UInteger8 clock_class(struct clock *c)
} }
struct clock *clock_create(int phc_index, struct interface *iface, int count, struct clock *clock_create(int phc_index, struct interface *iface, int count,
enum timestamp_type timestamping, struct defaultDS *ds, enum timestamp_type timestamping, struct defaultDS *ds)
struct port_defaults *pod)
{ {
int i, max_adj, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0; int i, max_adj, sw_ts = timestamping == TS_SOFTWARE ? 1 : 0;
struct clock *c = &the_clock; struct clock *c = &the_clock;
@ -267,7 +266,7 @@ struct clock *clock_create(int phc_index, struct interface *iface, int count,
c->fault_timeout = FAULT_RESET_SECONDS; c->fault_timeout = FAULT_RESET_SECONDS;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
c->port[i] = port_open(pod, phc_index, timestamping, 1+i, &iface[i], c); c->port[i] = port_open(phc_index, timestamping, 1+i, &iface[i], c);
if (!c->port[i]) { if (!c->port[i]) {
pr_err("failed to open port %s", iface[i].name); pr_err("failed to open port %s", iface[i].name);
return NULL; return NULL;

View File

@ -65,12 +65,10 @@ UInteger8 clock_class(struct clock *c);
* @param count The number of elements in @a interfaces. * @param count The number of elements in @a interfaces.
* @param timestamping The timestamping mode for this clock. * @param timestamping The timestamping mode for this clock.
* @param ds A pointer to a default data set for the clock. * @param ds A pointer to a default data set for the clock.
* @param pod A pointer to a default port data set for the clock.
* @return A pointer to the single global clock instance. * @return A pointer to the single global clock instance.
*/ */
struct clock *clock_create(int phc_index, struct interface *iface, int count, struct clock *clock_create(int phc_index, struct interface *iface, int count,
enum timestamp_type timestamping, struct defaultDS *ds, enum timestamp_type timestamping, struct defaultDS *ds);
struct port_defaults *pod);
/** /**
* Obtains a clock's default data set. * Obtains a clock's default data set.

View File

@ -177,6 +177,8 @@ int config_create_interface(char *name, struct config *cfg)
strncpy(iface->name, name, MAX_IFNAME_SIZE); strncpy(iface->name, name, MAX_IFNAME_SIZE);
iface->dm = cfg->dm; iface->dm = cfg->dm;
iface->transport = cfg->transport; iface->transport = cfg->transport;
memcpy(&iface->pod, &cfg->pod, sizeof(cfg->pod));
cfg->nports++; cfg->nports++;
return i; return i;

View File

@ -32,6 +32,7 @@ struct interface {
char name[MAX_IFNAME_SIZE + 1]; char name[MAX_IFNAME_SIZE + 1];
enum delay_mechanism dm; enum delay_mechanism dm;
enum transport_type transport; enum transport_type transport;
struct port_defaults pod;
}; };
struct config { struct config {

5
port.c
View File

@ -1537,8 +1537,7 @@ struct ptp_message *port_management_reply(struct PortIdentity pid,
return msg; return msg;
} }
struct port *port_open(struct port_defaults *pod, struct port *port_open(int phc_index,
int phc_index,
enum timestamp_type timestamping, enum timestamp_type timestamping,
int number, int number,
struct interface *interface, struct interface *interface,
@ -1561,7 +1560,7 @@ struct port *port_open(struct port_defaults *pod,
return NULL; return NULL;
} }
p->pod = *pod; p->pod = interface->pod;
p->name = interface->name; p->name = interface->name;
p->clock = clock; p->clock = clock;
p->trp = transport_create(interface->transport); p->trp = transport_create(interface->transport);

4
port.h
View File

@ -128,7 +128,6 @@ struct ptp_message *port_management_reply(struct PortIdentity pid,
/** /**
* Open a network port. * Open a network port.
* @param pod A pointer to a default port data set for this port.
* @param phc_index The PHC device index for the network device. * @param phc_index The PHC device index for the network device.
* @param timestamping The timestamping mode for this port. * @param timestamping The timestamping mode for this port.
* @param number An arbitrary number assigned to this port. * @param number An arbitrary number assigned to this port.
@ -136,8 +135,7 @@ struct ptp_message *port_management_reply(struct PortIdentity pid,
* @param clock A pointer to the system PTP clock. * @param clock A pointer to the system PTP clock.
* @return A pointer to an open port on success, or NULL otherwise. * @return A pointer to an open port on success, or NULL otherwise.
*/ */
struct port *port_open(struct port_defaults *pod, struct port *port_open(int phc_index,
int phc_index,
enum timestamp_type timestamping, enum timestamp_type timestamping,
int number, int number,
struct interface *interface, struct interface *interface,

View File

@ -112,7 +112,6 @@ int main(int argc, char *argv[])
enum timestamp_type *timestamping = &cfg_settings.timestamping; enum timestamp_type *timestamping = &cfg_settings.timestamping;
struct clock *clock; struct clock *clock;
struct defaultDS *ds = &cfg_settings.dds; struct defaultDS *ds = &cfg_settings.dds;
struct port_defaults *pod = &cfg_settings.pod;
int phc_index = -1; int phc_index = -1;
/* Process the command line arguments. */ /* Process the command line arguments. */
@ -222,7 +221,7 @@ int main(int argc, char *argv[])
ds->clockQuality.clockClass = 255; ds->clockQuality.clockClass = 255;
} }
clock = clock_create(phc_index, iface, *nports, *timestamping, ds, pod); clock = clock_create(phc_index, iface, *nports, *timestamping, ds);
if (!clock) { if (!clock) {
fprintf(stderr, "failed to create a clock\n"); fprintf(stderr, "failed to create a clock\n");
return -1; return -1;