From 9b27664cfc570ef9f00e1ded3e7fac2e8611e4cc Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Sun, 18 Oct 2015 17:19:43 +0200 Subject: [PATCH] clock: simplify the create method. With the new configuration API, there is no need to pass the default data set. Instead, the clock code can read the configuration directly. This patch simplifies the clock create method by removing the 'dds' parameter and moving the code that initialized the data set into the clock module. Signed-off-by: Richard Cochran --- clock.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- clock.h | 4 +-- ds.h | 5 ---- ptp4l.c | 85 ++--------------------------------------------------- 4 files changed, 86 insertions(+), 98 deletions(-) diff --git a/clock.c b/clock.c index acfc7a3..5198f72 100644 --- a/clock.c +++ b/clock.c @@ -799,8 +799,7 @@ static void clock_remove_port(struct clock *c, struct port *p) } struct clock *clock_create(struct config *config, int phc_index, - struct interfaces_head *ifaces, - struct default_ds *dds) + struct interfaces_head *ifaces) { enum timestamp_type timestamping = config_get_int(config, NULL, "time_stamping"); @@ -808,9 +807,10 @@ struct clock *clock_create(struct config *config, int phc_index, enum servo_type servo = config_get_int(config, NULL, "clock_servo"); struct clock *c = &the_clock; struct port *p; - char phc[32]; + unsigned char oui[OUI_LEN]; + char phc[32], *tmp; struct interface *udsif = &c->uds_interface; - struct interface *iface; + struct interface *iface = STAILQ_FIRST(ifaces); struct timespec ts; int sfl; @@ -820,6 +820,85 @@ struct clock *clock_create(struct config *config, int phc_index, if (c->nports) clock_destroy(c); + /* Initialize the defaultDS. */ + c->dds.clockQuality.clockClass = + config_get_int(config, NULL, "clockClass"); + c->dds.clockQuality.clockAccuracy = + config_get_int(config, NULL, "clockAccuracy"); + c->dds.clockQuality.offsetScaledLogVariance = + config_get_int(config, NULL, "offsetScaledLogVariance"); + + c->desc.productDescription.max_symbols = 64; + c->desc.revisionData.max_symbols = 32; + c->desc.userDescription.max_symbols = 128; + + tmp = config_get_string(config, NULL, "productDescription"); + if (count_char(tmp, ';') != 2 || + static_ptp_text_set(&c->desc.productDescription, tmp)) { + pr_err("invalid productDescription '%s'", tmp); + return NULL; + } + tmp = config_get_string(config, NULL, "revisionData"); + if (count_char(tmp, ';') != 2 || + static_ptp_text_set(&c->desc.revisionData, tmp)) { + pr_err("invalid revisionData '%s'", tmp); + return NULL; + } + tmp = config_get_string(config, NULL, "userDescription"); + if (static_ptp_text_set(&c->desc.userDescription, tmp)) { + pr_err("invalid userDescription '%s'", tmp); + return NULL; + } + tmp = config_get_string(config, NULL, "manufacturerIdentity"); + if (OUI_LEN != sscanf(tmp, "%hhx:%hhx:%hhx", &oui[0], &oui[1], &oui[2])) { + pr_err("invalid manufacturerIdentity '%s'", tmp); + return NULL; + } + memcpy(c->desc.manufacturerIdentity, oui, OUI_LEN); + + c->dds.domainNumber = config_get_int(config, NULL, "domainNumber"); + + if (config_get_int(config, NULL, "slaveOnly")) { + c->dds.flags |= DDS_SLAVE_ONLY; + } + if (config_get_int(config, NULL, "twoStepFlag")) { + c->dds.flags |= DDS_TWO_STEP_FLAG; + } + c->dds.priority1 = config_get_int(config, NULL, "priority1"); + c->dds.priority2 = config_get_int(config, NULL, "priority2"); + + if (!config_get_int(config, NULL, "gmCapable") && + c->dds.flags & DDS_SLAVE_ONLY) { + pr_err("Cannot mix 1588 slaveOnly with 802.1AS !gmCapable"); + return NULL; + } + if (!config_get_int(config, NULL, "gmCapable") || + c->dds.flags & DDS_SLAVE_ONLY) { + c->dds.clockQuality.clockClass = 255; + } + + if (!(c->dds.flags & DDS_TWO_STEP_FLAG)) { + switch (config_get_int(config, NULL, "time_stamping")) { + case TS_SOFTWARE: + case TS_LEGACY_HW: + pr_err("one step is only possible " + "with hardware time stamping"); + return NULL; + case TS_HARDWARE: + if (config_set_int(config, "time_stamping", TS_ONESTEP)) + return NULL; + break; + case TS_ONESTEP: + break; + } + } + + if (generate_clock_identity(&c->dds.clockIdentity, iface->name)) { + pr_err("failed to generate a clock identity"); + return NULL; + } + + /* Configure the UDS. */ snprintf(udsif->name, sizeof(udsif->name), "%s", config_get_string(config, NULL, "uds_address")); if (config_set_section_int(config, udsif->name, @@ -841,7 +920,6 @@ struct clock *clock_create(struct config *config, int phc_index, c->kernel_leap = config_get_int(config, NULL, "kernel_leap"); c->utc_offset = CURRENT_UTC_OFFSET; c->time_source = config_get_int(config, NULL, "timeSource"); - c->desc = dds->clock_desc; if (c->free_running) { c->clkid = CLOCK_INVALID; @@ -911,8 +989,6 @@ struct clock *clock_create(struct config *config, int phc_index, } } - c->dds = dds->dds; - /* Initialize the parentDS. */ clock_update_grandmaster(c); c->dad.pds.parentStats = 0; diff --git a/clock.h b/clock.h index 9a1151f..58ce129 100644 --- a/clock.h +++ b/clock.h @@ -72,12 +72,10 @@ struct config *clock_config(struct clock *c); * @param phc_index PTP hardware clock device to use. * Pass -1 to select CLOCK_REALTIME. * @param ifaces A queue of network interfaces. - * @param dds A pointer to a default data set for the clock. * @return A pointer to the single global clock instance. */ struct clock *clock_create(struct config *config, int phc_index, - struct interfaces_head *ifaces, - struct default_ds *dds); + struct interfaces_head *ifaces); /** * Obtains a clock's default data set. diff --git a/ds.h b/ds.h index 092a3c3..b36862d 100644 --- a/ds.h +++ b/ds.h @@ -50,11 +50,6 @@ struct clock_description { Octet manufacturerIdentity[OUI_LEN]; }; -struct default_ds { - struct defaultDS dds; - struct clock_description clock_desc; -}; - struct dataset { UInteger8 priority1; struct ClockIdentity identity; diff --git a/ptp4l.c b/ptp4l.c index e250e2f..0ccb4ba 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -39,8 +39,6 @@ int assume_two_step = 0; -static struct default_ds ptp4l_dds; - static void usage(char *progname) { fprintf(stderr, @@ -75,15 +73,12 @@ static void usage(char *progname) int main(int argc, char *argv[]) { - char *config = NULL, *req_phc = NULL, *progname, *tmp; + char *config = NULL, *req_phc = NULL, *progname; int c, err = -1; struct interface *iface; struct clock *clock = NULL; struct config *cfg; - struct default_ds *dds = &ptp4l_dds; - struct defaultDS *ds = &ptp4l_dds.dds; int phc_index = -1, print_level, required_modes = 0; - unsigned char oui[OUI_LEN]; if (handle_term_signals()) return -1; @@ -192,61 +187,6 @@ int main(int argc, char *argv[]) sk_check_fupsync = config_get_int(cfg, NULL, "check_fup_sync"); sk_tx_timeout = config_get_int(cfg, NULL, "tx_timestamp_timeout"); - ds->clockQuality.clockClass = config_get_int(cfg, NULL, "clockClass"); - ds->clockQuality.clockAccuracy = config_get_int(cfg, NULL, "clockAccuracy"); - ds->clockQuality.offsetScaledLogVariance = - config_get_int(cfg, NULL, "offsetScaledLogVariance"); - - dds->clock_desc.productDescription.max_symbols = 64; - dds->clock_desc.revisionData.max_symbols = 32; - dds->clock_desc.userDescription.max_symbols = 128; - - tmp = config_get_string(cfg, NULL, "productDescription"); - if (count_char(tmp, ';') != 2 || - static_ptp_text_set(&dds->clock_desc.productDescription, tmp)) { - fprintf(stderr, "invalid productDescription '%s'.\n", tmp); - goto out; - } - tmp = config_get_string(cfg, NULL, "revisionData"); - if (count_char(tmp, ';') != 2 || - static_ptp_text_set(&dds->clock_desc.revisionData, tmp)) { - fprintf(stderr, "invalid revisionData '%s'.\n", tmp); - goto out; - } - tmp = config_get_string(cfg, NULL, "userDescription"); - if (static_ptp_text_set(&dds->clock_desc.userDescription, tmp)) { - fprintf(stderr, "invalid userDescription '%s'.\n", tmp); - goto out; - } - tmp = config_get_string(cfg, NULL, "manufacturerIdentity"); - if (OUI_LEN != sscanf(tmp, "%hhx:%hhx:%hhx", &oui[0], &oui[1], &oui[2])) { - fprintf(stderr, "invalid manufacturerIdentity '%s'.\n", tmp); - goto out; - } - memcpy(dds->clock_desc.manufacturerIdentity, oui, OUI_LEN); - - ds->domainNumber = config_get_int(cfg, NULL, "domainNumber"); - - if (config_get_int(cfg, NULL, "slaveOnly")) { - ds->flags |= DDS_SLAVE_ONLY; - ds->clockQuality.clockClass = 248; - } - if (config_get_int(cfg, NULL, "twoStepFlag")) { - ds->flags |= DDS_TWO_STEP_FLAG; - } - ds->priority1 = config_get_int(cfg, NULL, "priority1"); - ds->priority2 = config_get_int(cfg, NULL, "priority2"); - - if (!config_get_int(cfg, NULL, "gmCapable") && - ds->flags & DDS_SLAVE_ONLY) { - fprintf(stderr, - "Cannot mix 1588 slaveOnly with 802.1AS !gmCapable.\n"); - goto out; - } - if (!config_get_int(cfg, NULL, "gmCapable") || - ds->flags & DDS_SLAVE_ONLY) { - ds->clockQuality.clockClass = 255; - } if (config_get_int(cfg, NULL, "clock_servo") == CLOCK_SERVO_NTPSHM) { config_set_int(cfg, "kernel_leap", 0); config_set_int(cfg, "sanity_freq_limit", 0); @@ -258,22 +198,6 @@ int main(int argc, char *argv[]) goto out; } - if (!(ds->flags & DDS_TWO_STEP_FLAG)) { - switch (config_get_int(cfg, NULL, "time_stamping")) { - case TS_SOFTWARE: - case TS_LEGACY_HW: - fprintf(stderr, "one step is only possible " - "with hardware time stamping\n"); - goto out; - case TS_HARDWARE: - if (config_set_int(cfg, "time_stamping", TS_ONESTEP)) - goto out; - break; - case TS_ONESTEP: - break; - } - } - switch (config_get_int(cfg, NULL, "time_stamping")) { case TS_SOFTWARE: required_modes |= SOF_TIMESTAMPING_TX_SOFTWARE | @@ -330,12 +254,7 @@ int main(int argc, char *argv[]) pr_info("selected /dev/ptp%d as PTP clock", phc_index); } - if (generate_clock_identity(&ds->clockIdentity, iface->name)) { - fprintf(stderr, "failed to generate a clock identity\n"); - goto out; - } - - clock = clock_create(cfg, phc_index, &cfg->interfaces, &ptp4l_dds); + clock = clock_create(cfg, phc_index, &cfg->interfaces); if (!clock) { fprintf(stderr, "failed to create a clock\n"); goto out;