Skip to contentSkip to conversation

iproute2: can: support CAN FD control interface

PATCH In review Oliver Hartkopp 2 participants 4 messages Apr 23, 2014 – May 9, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover iproute2: can: support CAN FD control interface

For CAN FD a new set of bittiming configuration and enabling functions for the data section is provided by the CAN driver infrastructure.

This patch set allows to configure the newly introduced CAN FD properties.

Tested with PEAK PCAN USB pro FD pilot series hardware.

Oliver Hartkopp (2):
iproute2: can: fix indention white spaces
iproute2: can: support CAN FD control interface

 ip/iplink_can.c | 144 +++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 107 insertions(+), 37 deletions(-)
Signature · 1 line
1.9.2
#1 lore raw

PATCH 1/2 iproute2: can: fix indention white spaces

When preparing a patch for CAN FD support these white space issues showed up. Fix it in the current code to be able to provide a proper follow up patch.

---
 ip/iplink_can.c | 72 ++++++++++++++++++++++++++++-----------------------------
 1 file changed, 36 insertions(+), 36 deletions(-)
ip/iplink_can.c +36 -36
index 1d3d09c..66e6c0e 100644
@@ -1,12 +1,12 @@
 /*
  * iplink_can.c	CAN device support
  *
- *              This program is free software; you can redistribute it and/or
- *              modify it under the terms of the GNU General Public License
- *              as published by the Free Software Foundation; either version
- *              2 of the License, or (at your option) any later version.
+ *		This program is free software; you can redistribute it and/or
+ *		modify it under the terms of the GNU General Public License
+ *		as published by the Free Software Foundation; either version
+ *		2 of the License, or (at your option) any later version.
  *
- * Authors:     Wolfgang Grandegger <[email protected]>
+ * Authors:	Wolfgang Grandegger <[email protected]>
  */
 
 #include <stdio.h>
@@ -23,27 +23,27 @@ static void usage(void)
 {
 	fprintf(stderr,
 		"Usage: ip link set DEVICE type can\n"
-	        "\t[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | \n"
-	        "\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n "
+		"\t[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | \n"
+		"\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n "
 		"\t  phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n"
 		"\n"
-	        "\t[ loopback { on | off } ]\n"
-	        "\t[ listen-only { on | off } ]\n"
-	        "\t[ triple-sampling { on | off } ]\n"
-	        "\t[ one-shot { on | off } ]\n"
-	        "\t[ berr-reporting { on | off } ]\n"
+		"\t[ loopback { on | off } ]\n"
+		"\t[ listen-only { on | off } ]\n"
+		"\t[ triple-sampling { on | off } ]\n"
+		"\t[ one-shot { on | off } ]\n"
+		"\t[ berr-reporting { on | off } ]\n"
 		"\n"
-	        "\t[ restart-ms TIME-MS ]\n"
-	        "\t[ restart ]\n"
+		"\t[ restart-ms TIME-MS ]\n"
+		"\t[ restart ]\n"
 		"\n"
-		"\tWhere: BITRATE       := { 1..1000000 }\n"
-		"\t       SAMPLE-POINT  := { 0.000..0.999 }\n"
-		"\t       TQ            := { NUMBER }\n"
-		"\t       PROP-SEG      := { 1..8 }\n"
-		"\t       PHASE-SEG1    := { 1..8 }\n"
-		"\t       PHASE-SEG2    := { 1..8 }\n"
-		"\t       SJW           := { 1..4 }\n"
-		"\t       RESTART-MS    := { 0 | NUMBER }\n"
+		"\tWhere: BITRATE	:= { 1..1000000 }\n"
+		"\t	  SAMPLE-POINT	:= { 0.000..0.999 }\n"
+		"\t	  TQ		:= { NUMBER }\n"
+		"\t	  PROP-SEG	:= { 1..8 }\n"
+		"\t	  PHASE-SEG1	:= { 1..8 }\n"
+		"\t	  PHASE-SEG2	:= { 1..8 }\n"
+		"\t	  SJW		:= { 1..4 }\n"
+		"\t	  RESTART-MS	:= { 0 | NUMBER }\n"
 		);
 }
 
@@ -185,12 +185,12 @@ static int can_parse_opt(struct link_util *lu, int argc, char **argv,
 }
 
 static const char *can_state_names[] = {
-		[CAN_STATE_ERROR_ACTIVE] = "ERROR-ACTIVE",
-		[CAN_STATE_ERROR_WARNING] = "ERROR-WARNING",
-		[CAN_STATE_ERROR_PASSIVE] = "ERROR-PASSIVE",
-		[CAN_STATE_BUS_OFF] = "BUS-OFF",
-		[CAN_STATE_STOPPED] = "STOPPED",
-		[CAN_STATE_SLEEPING] = "SLEEPING"
+	[CAN_STATE_ERROR_ACTIVE] = "ERROR-ACTIVE",
+	[CAN_STATE_ERROR_WARNING] = "ERROR-WARNING",
+	[CAN_STATE_ERROR_PASSIVE] = "ERROR-PASSIVE",
+	[CAN_STATE_BUS_OFF] = "BUS-OFF",
+	[CAN_STATE_STOPPED] = "STOPPED",
+	[CAN_STATE_SLEEPING] = "SLEEPING"
 };
 
 static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
@@ -228,10 +228,10 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 	if (tb[IFLA_CAN_BITTIMING]) {
 		struct can_bittiming *bt = RTA_DATA(tb[IFLA_CAN_BITTIMING]);
 
-		fprintf(f, "\n    "
+		fprintf(f, "\n	  "
 			"bitrate %d sample-point %.3f ",
-		        bt->bitrate, (float)bt->sample_point / 1000.);
-		fprintf(f, "\n    "
+			bt->bitrate, (float)bt->sample_point / 1000.);
+		fprintf(f, "\n	  "
 			"tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d",
 			bt->tq, bt->prop_seg, bt->phase_seg1, bt->phase_seg2,
 			bt->sjw);
@@ -241,10 +241,10 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 		struct can_bittiming_const *btc =
 			RTA_DATA(tb[IFLA_CAN_BITTIMING_CONST]);
 
-		fprintf(f, "\n    "
+		fprintf(f, "\n	  "
 			"%s: tseg1 %d..%d tseg2 %d..%d "
 			"sjw 1..%d brp %d..%d brp-inc %d",
-		        btc->name, btc->tseg1_min, btc->tseg1_max,
+			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);
 	}
@@ -252,7 +252,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 	if (tb[IFLA_CAN_CLOCK]) {
 		struct can_clock *clock = RTA_DATA(tb[IFLA_CAN_CLOCK]);
 
-		fprintf(f, "\n    clock %d", clock->freq);
+		fprintf(f, "\n	  clock %d", clock->freq);
 	}
 
 }
@@ -264,10 +264,10 @@ static void can_print_xstats(struct link_util *lu,
 
 	if (xstats && RTA_PAYLOAD(xstats) == sizeof(*stats)) {
 		stats = RTA_DATA(xstats);
-		fprintf(f, "\n    "
+		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, "\n	  %-10d %-10d %-10d %-10d %-10d %-10d",
 			stats->restarts, stats->bus_error,
 			stats->arbitration_lost, stats->error_warning,
 			stats->error_passive, stats->bus_off);
Signature · 1 line
1.9.2
#2 lore raw

PATCH 2/2 iproute2: can: support CAN FD control interface

In reply to Oliver Hartkopp

For CAN FD a new set of bittiming configuration and enabling functions for the data section is provided by the CAN driver infrastructure.

This patch allows to configure the newly introduced CAN FD properties.

---
 ip/iplink_can.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)
ip/iplink_can.c +71 -1
index 66e6c0e..3bef82a 100644
@@ -27,11 +27,16 @@ static void usage(void)
 		"\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n "
 		"\t  phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n"
 		"\n"
+		"\t[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] | \n"
+		"\t[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n "
+		"\t  dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]\n"
+		"\n"
 		"\t[ loopback { on | off } ]\n"
 		"\t[ listen-only { on | off } ]\n"
 		"\t[ triple-sampling { on | off } ]\n"
 		"\t[ one-shot { on | off } ]\n"
 		"\t[ berr-reporting { on | off } ]\n"
+		"\t[ fd { on | off } ]\n"
 		"\n"
 		"\t[ restart-ms TIME-MS ]\n"
 		"\t[ restart ]\n"
@@ -88,6 +93,7 @@ static void print_ctrlmode(FILE *f, __u32 cm)
 	_PF(CAN_CTRLMODE_3_SAMPLES, "TRIPLE-SAMPLING");
 	_PF(CAN_CTRLMODE_ONE_SHOT, "ONE-SHOT");
 	_PF(CAN_CTRLMODE_BERR_REPORTING, "BERR-REPORTING");
+	_PF(CAN_CTRLMODE_FD, "FD");
 #undef _PF
 	if (cm)
 		fprintf(f, "%x", cm);
@@ -97,10 +103,11 @@ static void print_ctrlmode(FILE *f, __u32 cm)
 static int can_parse_opt(struct link_util *lu, int argc, char **argv,
 			 struct nlmsghdr *n)
 {
-	struct can_bittiming bt;
+	struct can_bittiming bt, dbt;
 	struct can_ctrlmode cm = {0, 0};
 
 	memset(&bt, 0, sizeof(bt));
+	memset(&dbt, 0, sizeof(dbt));
 	while (argc > 0) {
 		if (matches(*argv, "bitrate") == 0) {
 			NEXT_ARG();
@@ -134,6 +141,37 @@ static int can_parse_opt(struct link_util *lu, int argc, char **argv,
 			NEXT_ARG();
 			if (get_u32(&bt.sjw, *argv, 0))
 				invarg("invalid \"sjw\" value\n", *argv);
+		} else if (matches(*argv, "dbitrate") == 0) {
+			NEXT_ARG();
+			if (get_u32(&dbt.bitrate, *argv, 0))
+				invarg("invalid \"dbitrate\" value\n", *argv);
+		} else if (matches(*argv, "dsample-point") == 0) {
+			float sp;
+
+			NEXT_ARG();
+			if (get_float(&sp, *argv))
+				invarg("invalid \"dsample-point\" value\n", *argv);
+			dbt.sample_point = (__u32)(sp * 1000);
+		} else if (matches(*argv, "dtq") == 0) {
+			NEXT_ARG();
+			if (get_u32(&dbt.tq, *argv, 0))
+				invarg("invalid \"dtq\" value\n", *argv);
+		} else if (matches(*argv, "dprop-seg") == 0) {
+			NEXT_ARG();
+			if (get_u32(&dbt.prop_seg, *argv, 0))
+				invarg("invalid \"dprop-seg\" value\n", *argv);
+		} else if (matches(*argv, "dphase-seg1") == 0) {
+			NEXT_ARG();
+			if (get_u32(&dbt.phase_seg1, *argv, 0))
+				invarg("invalid \"dphase-seg1\" value\n", *argv);
+		} else if (matches(*argv, "dphase-seg2") == 0) {
+			NEXT_ARG();
+			if (get_u32(&dbt.phase_seg2, *argv, 0))
+				invarg("invalid \"dphase-seg2\" value\n", *argv);
+		} else if (matches(*argv, "dsjw") == 0) {
+			NEXT_ARG();
+			if (get_u32(&dbt.sjw, *argv, 0))
+				invarg("invalid \"dsjw\" value\n", *argv);
 		} else if (matches(*argv, "loopback") == 0) {
 			NEXT_ARG();
 			set_ctrlmode("loopback", *argv, &cm,
@@ -154,6 +192,10 @@ static int can_parse_opt(struct link_util *lu, int argc, char **argv,
 			NEXT_ARG();
 			set_ctrlmode("berr-reporting", *argv, &cm,
 				     CAN_CTRLMODE_BERR_REPORTING);
+		} else if (matches(*argv, "fd") == 0) {
+			NEXT_ARG();
+			set_ctrlmode("fd", *argv, &cm,
+				     CAN_CTRLMODE_FD);
 		} else if (matches(*argv, "restart") == 0) {
 			__u32 val = 1;
 
@@ -178,6 +220,8 @@ static int can_parse_opt(struct link_util *lu, int argc, char **argv,
 
 	if (bt.bitrate || bt.tq)
 		addattr_l(n, 1024, IFLA_CAN_BITTIMING, &bt, sizeof(bt));
+	if (dbt.bitrate || dbt.tq)
+		addattr_l(n, 1024, IFLA_CAN_DATA_BITTIMING, &dbt, sizeof(dbt));
 	if (cm.mask)
 		addattr_l(n, 1024, IFLA_CAN_CTRLMODE, &cm, sizeof(cm));
 
@@ -249,6 +293,32 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 			btc->brp_min, btc->brp_max, btc->brp_inc);
 	}
 
+	if (tb[IFLA_CAN_DATA_BITTIMING]) {
+		struct can_bittiming *dbt =
+			RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]);
+
+		fprintf(f, "\n	  "
+			"dbitrate %d dsample-point %.3f ",
+			dbt->bitrate, (float)dbt->sample_point / 1000.);
+		fprintf(f, "\n	  "
+			"dtq %d dprop-seg %d dphase-seg1 %d "
+			"dphase-seg2 %d dsjw %d",
+			dbt->tq, dbt->prop_seg, dbt->phase_seg1,
+			dbt->phase_seg2, dbt->sjw);
+	}
+
+	if (tb[IFLA_CAN_DATA_BITTIMING_CONST]) {
+		struct can_bittiming_const *dbtc =
+			RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING_CONST]);
+
+		fprintf(f, "\n	  "
+			"%s: dtseg1 %d..%d dtseg2 %d..%d "
+			"dsjw 1..%d dbrp %d..%d dbrp-inc %d",
+			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);
+	}
+
 	if (tb[IFLA_CAN_CLOCK]) {
 		struct can_clock *clock = RTA_DATA(tb[IFLA_CAN_CLOCK]);
 
Signature · 1 line
1.9.2
#3 lore raw
In reply to Oliver Hartkopp
Quoted 5 lines · On Wed, 23 Apr 2014 19:27:25 +0200 Oliver Hartkopp <[email protected]>…

For CAN FD a new set of bittiming configuration and enabling functions for the data section is provided by the CAN driver infrastructure.

This patch set allows to configure the newly introduced CAN FD properties.

Quoted 9 lines

Tested with PEAK PCAN USB pro FD pilot series hardware.

Oliver Hartkopp (2):
iproute2: can: fix indention white spaces
iproute2: can: support CAN FD control interface

 ip/iplink_can.c | 144 +++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 107 insertions(+), 37 deletions(-)

Accepted