Skip to content

Commit

Permalink
adding speed field information for interface
Browse files Browse the repository at this point in the history
Get the interface speed related information using ethtool and
convert interface speed to bit rate in attoseconds per bit.

v4: adding interface bit period in iface_if_info. This bit period
    is updated during init time and whenever there are port events
    like link up and down and speed updates.

Signed-off-by: Greg Armstrong <greg.armstrong.uw@renesas.com>
Signed-off-by: Leon Goldin <leon.goldin.nx@renesas.com>
Signed-off-by: Devasish Dey <devasish.dey@syncmonk.net>
Signed-off-by: Vipin Sharma <vipin.sharma@syncmonk.net>
  • Loading branch information
syncmonk authored and richardcochran committed Feb 5, 2023
1 parent 0c4ea4d commit 3d245ba
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,13 @@ struct clock *clock_create(enum clock_type type, struct config *config,
memset(ts_label, 0, sizeof(ts_label));
if (!rtnl_get_ts_device(interface_name(iface), ts_label))
interface_set_label(iface, ts_label);
/* Interface speed information */
interface_get_ifinfo(iface);
interface_get_tsinfo(iface);
if (interface_tsinfo_valid(iface) &&
!interface_tsmodes_supported(iface, required_modes)) {
!interface_tsmodes_supported(iface, required_modes)) {
pr_err("interface '%s' does not support requested timestamping mode",
interface_name(iface));
interface_name(iface));
return NULL;
}
}
Expand Down
12 changes: 12 additions & 0 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct interface {
char name[MAX_IFNAME_SIZE + 1];
char ts_label[MAX_IFNAME_SIZE + 1];
struct sk_ts_info ts_info;
struct sk_if_info if_info;
int vclock;
};

Expand Down Expand Up @@ -40,11 +41,22 @@ int interface_get_tsinfo(struct interface *iface)
return sk_get_ts_info(iface->ts_label, &iface->ts_info);
}

int interface_get_ifinfo(struct interface *iface)
{
return sk_get_if_info(iface->ts_label, &iface->if_info);
}

const char *interface_label(struct interface *iface)
{
return iface->ts_label;
}

bool interface_ifinfo_valid(struct interface *iface)
{
return iface->if_info.valid ? true : false;
}


const char *interface_name(struct interface *iface)
{
return iface->name;
Expand Down
14 changes: 14 additions & 0 deletions interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ void interface_destroy(struct interface *iface);
*/
int interface_get_tsinfo(struct interface *iface);

/**
* Populate the time stamping information of a given interface.
* @param iface The interface of interest.
* @return zero on success, negative on failure.
*/
int interface_get_ifinfo(struct interface *iface);

/**
* Obtain the time stamping label of a network interface. This can be
* different from the name of the interface when bonding is in effect.
Expand Down Expand Up @@ -77,6 +84,13 @@ void interface_set_label(struct interface *iface, const char *label);
*/
bool interface_tsinfo_valid(struct interface *iface);

/**
* Tests whether an interface's interface information is valid or not.
* @param iface The interface of interest.
* @return True if the interface information is valid, false otherwise.
*/
bool interface_ifinfo_valid(struct interface *iface);

/**
* Tests whether an interface supports a set of given time stamping modes.
* @param iface The interface of interest.
Expand Down
5 changes: 5 additions & 0 deletions port.c
Original file line number Diff line number Diff line change
Expand Up @@ -2741,6 +2741,11 @@ void port_link_status(void *ctx, int linkup, int ts_index)
p->link_status = link_state;
} else {
p->link_status = link_state | LINK_STATE_CHANGED;
/* Update Interface speed information on Link up*/
if (linkup) {
interface_get_ifinfo(p->iface);
}

pr_notice("%s: link %s", p->log_name, linkup ? "up" : "down");
}

Expand Down
2 changes: 2 additions & 0 deletions sk.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ int sk_get_if_info(const char *name, struct sk_if_info *if_info)
if_info->valid = 1;
if_info->speed = ecmd.req.speed;

/* Megabits per second converted to attoseconds per bit */
if_info->iface_bit_period = (1000000000000ULL/if_info->speed);
return 0;
failed:
#endif
Expand Down
2 changes: 2 additions & 0 deletions sk.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ struct sk_ts_info {
* Contains interface information returned by the GLINKSETTINGS ioctl.
* @valid: set to non-zero when the info struct contains valid data.
* @speed: interface speed.
* @iface_bit_period interface bit period in attoseconds per bit.
*/
struct sk_if_info {
bool valid;
uint32_t speed;
uint64_t iface_bit_period;
};

/**
Expand Down

0 comments on commit 3d245ba

Please sign in to comment.