* [PATCH iproute2 5.11 1/2] iplink_can: add Classical CAN frame LEN8_DLC support
@ 2020-12-25 19:10 Oliver Hartkopp
2020-12-25 19:10 ` [PATCH iproute2 5.11 2/2] iplink_can: fix format output for details with statistics Oliver Hartkopp
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Hartkopp @ 2020-12-25 19:10 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, linux-can, Oliver Hartkopp
The len8_dlc element is filled by the CAN interface driver and used for CAN
frame creation by the CAN driver when the CAN_CTRLMODE_CC_LEN8_DLC flag is
supported by the driver and enabled via netlink configuration interface.
Add the command line support for cc-len8-dlc for Linux 5.11+
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
ip/iplink_can.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/ip/iplink_can.c b/ip/iplink_can.c
index 735ab941..6a26f3ff 100644
--- a/ip/iplink_can.c
+++ b/ip/iplink_can.c
@@ -35,10 +35,11 @@ static void print_usage(FILE *f)
"\t[ one-shot { on | off } ]\n"
"\t[ berr-reporting { on | off } ]\n"
"\t[ fd { on | off } ]\n"
"\t[ fd-non-iso { on | off } ]\n"
"\t[ presume-ack { on | off } ]\n"
+ "\t[ cc-len8-dlc { on | off } ]\n"
"\n"
"\t[ restart-ms TIME-MS ]\n"
"\t[ restart ]\n"
"\n"
"\t[ termination { 0..65535 } ]\n"
@@ -101,10 +102,11 @@ static void print_ctrlmode(FILE *f, __u32 cm)
_PF(CAN_CTRLMODE_ONE_SHOT, "ONE-SHOT");
_PF(CAN_CTRLMODE_BERR_REPORTING, "BERR-REPORTING");
_PF(CAN_CTRLMODE_FD, "FD");
_PF(CAN_CTRLMODE_FD_NON_ISO, "FD-NON-ISO");
_PF(CAN_CTRLMODE_PRESUME_ACK, "PRESUME-ACK");
+ _PF(CAN_CTRLMODE_CC_LEN8_DLC, "CC-LEN8-DLC");
#undef _PF
if (cm)
print_hex(PRINT_ANY, NULL, "%x", cm);
close_json_array(PRINT_ANY, "> ");
}
@@ -209,10 +211,14 @@ static int can_parse_opt(struct link_util *lu, int argc, char **argv,
CAN_CTRLMODE_FD_NON_ISO);
} else if (matches(*argv, "presume-ack") == 0) {
NEXT_ARG();
set_ctrlmode("presume-ack", *argv, &cm,
CAN_CTRLMODE_PRESUME_ACK);
+ } else if (matches(*argv, "cc-len8-dlc") == 0) {
+ NEXT_ARG();
+ set_ctrlmode("cc-len8-dlc", *argv, &cm,
+ CAN_CTRLMODE_CC_LEN8_DLC);
} else if (matches(*argv, "restart") == 0) {
__u32 val = 1;
addattr32(n, 1024, IFLA_CAN_RESTART, val);
} else if (matches(*argv, "restart-ms") == 0) {
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH iproute2 5.11 2/2] iplink_can: fix format output for details with statistics
2020-12-25 19:10 [PATCH iproute2 5.11 1/2] iplink_can: add Classical CAN frame LEN8_DLC support Oliver Hartkopp
@ 2020-12-25 19:10 ` Oliver Hartkopp
2020-12-26 17:48 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Hartkopp @ 2020-12-25 19:10 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, linux-can, Oliver Hartkopp
In commit 36e584ad8af6 ("iplink_can: fix format output of clock with
flag -details") from Antonio Borneo a single space has been added to
separate the CAN controller clock value from the numtxqueues value
which is printed in ipaddress.c directly after the CAN info output.
To maintain a common indention every line in the CAN info output now
ends with eight spaces on the next line. While commit 36e584ad8af6
fixed the '-details' option, the '-statistics' option now works too.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
ip/iplink_can.c | 60 +++++++++++++++++++++++++++----------------------
1 file changed, 33 insertions(+), 27 deletions(-)
diff --git a/ip/iplink_can.c b/ip/iplink_can.c
index 6a26f3ff..592b036e 100644
--- a/ip/iplink_can.c
+++ b/ip/iplink_can.c
@@ -272,10 +272,15 @@ static void can_print_json_timing_min_max(const char *attr, int min, int max)
print_int(PRINT_JSON, "min", NULL, min);
print_int(PRINT_JSON, "max", NULL, max);
close_json_object();
}
+/* all our lines end with 8 spaces in the next line to align numtxqueue
+ * output which is just added in ipaddress.c after the CAN info.
+ * The indention of 8 consists of 4 spaces + link_type ("can") + 1 space
+ * as provided by print_linktype() in ipaddress.c */
+
static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{
if (!tb)
return;
@@ -315,10 +320,12 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
"restart_ms",
"restart-ms %d ",
*restart_ms);
}
+ fprintf(f, "\n ");
+
/* bittiming is irrelevant if fixed bitrate is defined */
if (tb[IFLA_CAN_BITTIMING] && !tb[IFLA_CAN_BITRATE_CONST]) {
struct can_bittiming *bt = RTA_DATA(tb[IFLA_CAN_BITTIMING]);
if (is_json_context()) {
@@ -337,14 +344,14 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
print_int(PRINT_ANY, "phase_seg2",
NULL, bt->phase_seg2);
print_int(PRINT_ANY, "sjw", NULL, bt->sjw);
close_json_object();
} else {
- fprintf(f, "\n bitrate %d sample-point %.3f ",
+ fprintf(f, "bitrate %d sample-point %.3f\n ",
bt->bitrate, (float) bt->sample_point / 1000.);
- fprintf(f,
- "\n tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d",
+ fprintf(f, "tq %d prop-seg %d phase-seg1 %d phase-seg2"
+ "%d sjw %d\n ",
bt->tq, bt->prop_seg,
bt->phase_seg1, bt->phase_seg2,
bt->sjw);
}
}
@@ -368,12 +375,12 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
btc->brp_min,
btc->brp_max);
print_int(PRINT_JSON, "brp_inc", NULL, btc->brp_inc);
close_json_object();
} else {
- fprintf(f, "\n %s: tseg1 %d..%d tseg2 %d..%d "
- "sjw 1..%d brp %d..%d brp-inc %d",
+ fprintf(f, "%s: tseg1 %d..%d tseg2 %d..%d "
+ "sjw 1..%d brp %d..%d brp-inc %d\n ",
btc->name, btc->tseg1_min, btc->tseg1_max,
btc->tseg2_min, btc->tseg2_max, btc->sjw_max,
btc->brp_min, btc->brp_max, btc->brp_inc);
}
}
@@ -399,24 +406,24 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
for (i = 0; i < bitrate_cnt; ++i)
print_uint(PRINT_JSON, NULL, NULL,
bitrate_const[i]);
close_json_array(PRINT_JSON, NULL);
} else {
- fprintf(f, "\n bitrate %u", bitrate);
- fprintf(f, "\n [");
+ fprintf(f, "bitrate %u\n ", bitrate);
+ fprintf(f, "[");
for (i = 0; i < bitrate_cnt - 1; ++i) {
/* This will keep lines below 80 signs */
if (!(i % 6) && i)
- fprintf(f, "\n ");
+ fprintf(f, "\n ");
fprintf(f, "%8u, ", bitrate_const[i]);
}
if (!(i % 6) && i)
- fprintf(f, "\n ");
- fprintf(f, "%8u ]", bitrate_const[i]);
+ fprintf(f, "\n ");
+ fprintf(f, "%8u ]\n ", bitrate_const[i]);
}
}
/* data bittiming is irrelevant if fixed bitrate is defined */
if (tb[IFLA_CAN_DATA_BITTIMING] && !tb[IFLA_CAN_DATA_BITRATE_CONST]) {
@@ -439,15 +446,15 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
print_int(PRINT_JSON, "phase_seg2",
NULL, dbt->phase_seg2);
print_int(PRINT_JSON, "sjw", NULL, dbt->sjw);
close_json_object();
} else {
- fprintf(f, "\n dbitrate %d dsample-point %.3f ",
+ fprintf(f, "dbitrate %d dsample-point %.3f\n ",
dbt->bitrate,
(float) dbt->sample_point / 1000.);
- fprintf(f, "\n dtq %d dprop-seg %d dphase-seg1 %d "
- "dphase-seg2 %d dsjw %d",
+ fprintf(f, "dtq %d dprop-seg %d dphase-seg1 %d "
+ "dphase-seg2 %d dsjw %d\n ",
dbt->tq, dbt->prop_seg, dbt->phase_seg1,
dbt->phase_seg2, dbt->sjw);
}
}
@@ -472,12 +479,12 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
dbtc->brp_max);
print_int(PRINT_JSON, "brp_inc", NULL, dbtc->brp_inc);
close_json_object();
} else {
- fprintf(f, "\n %s: dtseg1 %d..%d dtseg2 %d..%d "
- "dsjw 1..%d dbrp %d..%d dbrp-inc %d",
+ fprintf(f, "%s: dtseg1 %d..%d dtseg2 %d..%d "
+ "dsjw 1..%d dbrp %d..%d dbrp-inc %d\n ",
dbtc->name, dbtc->tseg1_min, dbtc->tseg1_max,
dbtc->tseg2_min, dbtc->tseg2_max, dbtc->sjw_max,
dbtc->brp_min, dbtc->brp_max, dbtc->brp_inc);
}
}
@@ -504,24 +511,24 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
for (i = 0; i < dbitrate_cnt; ++i)
print_uint(PRINT_JSON, NULL, NULL,
dbitrate_const[i]);
close_json_array(PRINT_JSON, NULL);
} else {
- fprintf(f, "\n dbitrate %u", dbitrate);
- fprintf(f, "\n [");
+ fprintf(f, "dbitrate %u\n ", dbitrate);
+ fprintf(f, "[");
for (i = 0; i < dbitrate_cnt - 1; ++i) {
/* This will keep lines below 80 signs */
if (!(i % 6) && i)
- fprintf(f, "\n ");
+ fprintf(f, "\n ");
fprintf(f, "%8u, ", dbitrate_const[i]);
}
if (!(i % 6) && i)
- fprintf(f, "\n ");
- fprintf(f, "%8u ]", dbitrate_const[i]);
+ fprintf(f, "\n ");
+ fprintf(f, "%8u ]\n ", dbitrate_const[i]);
}
}
if (tb[IFLA_CAN_TERMINATION_CONST] && tb[IFLA_CAN_TERMINATION]) {
__u16 *trm = RTA_DATA(tb[IFLA_CAN_TERMINATION]);
@@ -535,28 +542,27 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
open_json_array(PRINT_JSON, "termination_const");
for (i = 0; i < trm_cnt; ++i)
print_hu(PRINT_JSON, NULL, NULL, trm_const[i]);
close_json_array(PRINT_JSON, NULL);
} else {
- fprintf(f, "\n termination %hu [ ", *trm);
+ fprintf(f, "termination %hu [ ", *trm);
for (i = 0; i < trm_cnt - 1; ++i)
fprintf(f, "%hu, ", trm_const[i]);
- fprintf(f, "%hu ]", trm_const[i]);
+ fprintf(f, "%hu ]\n ", trm_const[i]);
}
}
if (tb[IFLA_CAN_CLOCK]) {
struct can_clock *clock = RTA_DATA(tb[IFLA_CAN_CLOCK]);
print_int(PRINT_ANY,
"clock",
- "\n clock %d ",
+ "clock %d\n ",
clock->freq);
}
-
}
static void can_print_xstats(struct link_util *lu,
FILE *f, struct rtattr *xstats)
{
@@ -576,13 +582,13 @@ static void can_print_xstats(struct link_util *lu,
NULL, stats->error_warning);
print_int(PRINT_JSON, "error_passive",
NULL, stats->error_passive);
print_int(PRINT_JSON, "bus_off", NULL, stats->bus_off);
} else {
- fprintf(f, "\n re-started bus-errors arbit-lost "
- "error-warn error-pass bus-off");
- fprintf(f, "\n %-10d %-10d %-10d %-10d %-10d %-10d",
+ fprintf(f, "re-started bus-errors arbit-lost "
+ "error-warn error-pass bus-off\n ");
+ fprintf(f, "%-10d %-10d %-10d %-10d %-10d %-10d\n ",
stats->restarts, stats->bus_error,
stats->arbitration_lost, stats->error_warning,
stats->error_passive, stats->bus_off);
}
}
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2 5.11 2/2] iplink_can: fix format output for details with statistics
2020-12-25 19:10 ` [PATCH iproute2 5.11 2/2] iplink_can: fix format output for details with statistics Oliver Hartkopp
@ 2020-12-26 17:48 ` Stephen Hemminger
0 siblings, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2020-12-26 17:48 UTC (permalink / raw)
To: Oliver Hartkopp; +Cc: netdev, linux-can
On Fri, 25 Dec 2020 20:10:15 +0100
Oliver Hartkopp <socketcan@hartkopp.net> wrote:
> @@ -315,10 +320,12 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
> "restart_ms",
> "restart-ms %d ",
> *restart_ms);
> }
>
> + fprintf(f, "\n ");
> +
That will print in both JSON and non-JSON mode. You don't want to do that.
It also will break in single-line mode.
The iplink_can code has way too many if (is_json_context()) ...
which can lead to differences in output.
Ideally it should have no instances of "fprintf(f, ..."
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-26 17:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-25 19:10 [PATCH iproute2 5.11 1/2] iplink_can: add Classical CAN frame LEN8_DLC support Oliver Hartkopp
2020-12-25 19:10 ` [PATCH iproute2 5.11 2/2] iplink_can: fix format output for details with statistics Oliver Hartkopp
2020-12-26 17:48 ` Stephen Hemminger
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.