Skip to content

Commit e3fd170

Browse files
jukkarMaureenHelm
authored andcommitted
net: gptp: Allow user to tweak priority1 and priority2 values
Instead of hardcoding the priority1 and priority2 values used in BMCA, let the user tweak the values via Kconfig. Fixes zephyrproject-rtos#28151 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 5d473dc commit e3fd170

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

include/net/gptp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ extern "C" {
3434

3535
#define GPTP_PRIORITY1_NON_GM_CAPABLE 255
3636
#define GPTP_PRIORITY1_GM_CAPABLE 248
37+
38+
#if defined(CONFIG_NET_GPTP_BMCA_PRIORITY2)
39+
#define GPTP_PRIORITY2_DEFAULT CONFIG_NET_GPTP_BMCA_PRIORITY2
40+
#else
3741
#define GPTP_PRIORITY2_DEFAULT 248
42+
#endif
3843

3944
/** @endcond */
4045

subsys/net/l2/ethernet/gptp/Kconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,31 @@ config NET_GPTP_PATH_TRACE_ELEMENTS
195195
Announce message. Each array element takes 8 bytes. If this value
196196
is set to 8, then 8 * 8 = 64 bytes of memory is used.
197197

198+
config NET_GPTP_BMCA_PRIORITY1
199+
int "BMCA priority1 value"
200+
default 248 if NET_GPTP_GM_CAPABLE
201+
default 255
202+
range 0 255
203+
help
204+
The priority1 attribute of the local clock. It is used in the
205+
Best Master Clock selection Algorithm (BMCA), lower values take
206+
precedence. The default value is 255 if the device is non grand
207+
master capable, and 248 if it is GM capable.
208+
See Chapter 8.6.2.1 of IEEE 802.1AS for a more detailed description
209+
of priority1. Note that if the system is non GM capable, then the
210+
value 255 is used always and this setting is ignored.
211+
212+
config NET_GPTP_BMCA_PRIORITY2
213+
int "BMCA priority2 value"
214+
default 248
215+
range 0 255
216+
help
217+
The priority2 attribute of the local clock. It is used in the BMCA
218+
(Best Master Clock selection Algorithm), lower values take
219+
precedence. The default value is 248.
220+
See Chapter 8.6.2.5 of IEEE 802.1AS for a more detailed description
221+
of priority2.
222+
198223
config NET_GPTP_STATISTICS
199224
bool "Collect gPTP statistics"
200225
help

subsys/net/l2/ethernet/gptp/gptp.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,15 @@ static void gptp_init_clock_ds(void)
382382
GPTP_OFFSET_SCALED_LOG_VAR_UNKNOWN;
383383

384384
if (default_ds->gm_capable) {
385-
default_ds->priority1 = GPTP_PRIORITY1_GM_CAPABLE;
385+
/* The priority1 value cannot be 255 for GM capable
386+
* system.
387+
*/
388+
if (CONFIG_NET_GPTP_BMCA_PRIORITY1 ==
389+
GPTP_PRIORITY1_NON_GM_CAPABLE) {
390+
default_ds->priority1 = GPTP_PRIORITY1_GM_CAPABLE;
391+
} else {
392+
default_ds->priority1 = CONFIG_NET_GPTP_BMCA_PRIORITY1;
393+
}
386394
} else {
387395
default_ds->priority1 = GPTP_PRIORITY1_NON_GM_CAPABLE;
388396
}

0 commit comments

Comments
 (0)